...
This commit is contained in:
@ -24,13 +24,6 @@ public class Shooting : MonoBehaviour
|
||||
public GameObject gun;
|
||||
void Update()
|
||||
{
|
||||
/*if (Input.GetButtonDown("Fire1"))
|
||||
{
|
||||
Prefab = Random.Range(0, 1);
|
||||
Instantiate(Prefabs[Prefab], FirePoint.transform.position, FirePoint.transform.rotation);
|
||||
Shoot();
|
||||
}*/
|
||||
//if(Input.GetButtonDown("")
|
||||
if (Input.GetMouseButton(0) && fireCountdown <= 0f)
|
||||
{
|
||||
Instantiate(Prefabs[Prefab], FirePoint.transform.position, FirePoint.transform.rotation);
|
||||
@ -41,27 +34,14 @@ public class Shooting : MonoBehaviour
|
||||
fireCountdown -= Time.deltaTime;
|
||||
}
|
||||
|
||||
void Shoot()
|
||||
public void Shoot()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(raycast.transform.position, raycast.transform.forward, out hit, range))
|
||||
if (Physics.Raycast(raycast.transform.position, raycast.transform.forward, out var hit, range))
|
||||
{
|
||||
Debug.Log(hit.transform.name);
|
||||
|
||||
Target target = hit.transform.GetComponent<Target>();
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
if (hit.transform.TryGetComponent<Target>(out var target))
|
||||
target.TakeDamage(damage);
|
||||
}
|
||||
RotateToGunDirection(gun, hit.point);
|
||||
}
|
||||
}
|
||||
|
||||
void RotateToGunDirection(GameObject obj, Vector3 destination)
|
||||
{
|
||||
direction = destination - obj.transform.position;
|
||||
rotation = Quaternion.LookRotation(direction);
|
||||
obj.transform.localRotation = Quaternion.Lerp(obj.transform.rotation, rotation, 1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user