using System.Collections;

using System.Collections.Generic;

using UnityEditor.PackageManager;

using UnityEngine;


public class Spin : MonoBehaviour

{

public GameObject bullet;//子弹

public Transform bulletproduce;//子弹生成地

private Vector3 targetPosition = Vector3.zero;//鼠标坐标

private float nextFire;//间隔时间

public float fireRate=0.1f;//间隔发射时间大小


// Update is called once per frame

void Update()

{

Ray ray= Camera.main.ScreenPointToRay(Input.mousePosition);//把鼠标的点转化成射线

RaycastHit hitInfo;//碰撞信息

bool isCollider = Physics.Raycast(ray, out hitInfo);//保存位置信息

//实现点击效果过

if(isCollider&&hitInfo.collider.tag==Tags.ground)//有碰撞信息是否为地面

{

//isMoving = true;

LookAtTarget(hitInfo.point);

}

if(Input.GetMouseButton(0)&&Time.time>nextFire)

{

nextFire = Time.time + fireRate;

Instantiate(bullet,bulletproduce.position,bulletproduce.rotation);//生成子弹

}

}


void LookAtTarget(Vector3 hitPoint)

{

targetPosition = hitPoint;//鼠标位置等于碰撞位置

targetPosition = new Vector3(targetPosition.x, transform.position.y, targetPosition.z);//只取鼠标x轴和z轴位置

this.transform.LookAt(targetPosition);//看向鼠标所在的位置

}

}



using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Tags : MonoBehaviour

{

public const string ground = "Ground";

public const string player = "Player";

}