private void OnTriggerEnter(Collider other) { Debug.Log(other.name); target = GameObject.FindWithTag("Player"); if (other.gameObject.tag != target.tag && other.gameObject.tag != "Help") { Enemy2 enemy = other.GetComponent <Enemy2>(); if (enemy != null) { enemy.DamageEnemy(damage); } Destroy(gameObject); } }
void Shooot() { RaycastHit hit; if (Physics.Raycast(camera.transform.position, camera.transform.forward, out hit, range)) { if (hit.transform.tag != "Player") { Debug.Log(hit.transform.name); Enemy2 enemy = hit.transform.GetComponent <Enemy2>(); if (enemy != null) { enemy.DamageEnemy(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(hit.normal); } GameObject Bullet = Instantiate(bullet, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(Bullet, 0.1f); } } }