void Update () {
RaycastHit hit;
Vector3 forward = transform.TransformDirection (transform.up) * 1;
Debug.DrawRay (transform.position,transform.up,Color.green);
if(Physics.Raycast (transform.position,(transform.up), out hit)) {
Debug.DrawRay (transform.position,transform.up,Color.red);
if(hit.transform.gameObject.tag == "Enemy"&& Input.GetMouseButtonDown(0)) {
shoot = true;
print ("SHOOOt");
AIisDead = true;
Destroy (hit.GameObject);
}
´(This is a script attached to a gun)
When the raycast hits a object with the tag enemy, that object needs to be destroyed. But i cant really find out how to do it. the “hit” is that object the raycast is “touching”. And that is the object i want to destroy if i press the mouse button and the object is tagged enemy.
I tried doing in the way that from my enemys script, i destroy if the AIisDead from this script, is true.
But that destroyed all the enemys in the scene.