This commit is contained in:
2022-05-15 18:24:43 +07:00
parent abf262095f
commit bb6aea8720
22 changed files with 5008 additions and 170 deletions

View File

@ -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);
}
}