// Update is called once per frame void Update() { Debug.DrawRay(gunEnd.position, -transform.up); if (Input.GetButtonDown("Fire1")) { for (int i = 0; i < shotsCount; i++) { RaycastHit hit; Vector3 dir = -transform.up; dir = Quaternion.Euler(0, Random.Range(-angle, angle), 0) * dir; ShotRayScript shotRayInstance = Instantiate(shotRay, gunEnd.position, Quaternion.identity).GetComponent <ShotRayScript>(); if (Physics.Raycast(gunEnd.position, dir, out hit, range)) { shotRayInstance.DrawLine(gunEnd.position, hit.point); if (hit.collider.gameObject.tag == "Enemy") { CharachterBehaviour cb = hit.collider.gameObject.GetComponent <CharachterBehaviour>(); cb.ApplyDamage(damage); } } else { shotRayInstance.DrawLine(gunEnd.position, gunEnd.position + dir * range); } } } }
public void ZombieAttackHitEvent() { RaycastHit hit; if (Physics.Raycast(raycastStart.position, transform.forward, out hit, attackRange)) { if (hit.collider.gameObject.tag == "Player") { CharachterBehaviour cb = hit.collider.gameObject.GetComponent <CharachterBehaviour>(); cb.ApplyDamage(damage); } } }