I have this script which casts a ray when the mouse button is clicked
var Bullet1_direction = Vector3(15,0,45);
var Bullet2_direction = Vector3(0 ,0,1);
var Bullet3_direction = Vector3(-9 ,0,45);
var length = 4;
function Update () {
var Bullet1_diagonal = transform.TransformDirection(Bullet1_direction);
Bullet1_diagonal.Normalize();
var Bullet2_diagonal = transform.TransformDirection(Bullet2_direction);
Bullet2_diagonal.Normalize();
var Bullet3_diagonal = transform.TransformDirection(Bullet3_direction);
Bullet3_diagonal.Normalize();
if(Input.GetMouseButtonDown(0)){
Debug.DrawRay(transform.position, Bullet1_diagonal * length,Color.red);
Debug.DrawRay(transform.position, Bullet2_diagonal * length,Color.red);
Debug.DrawRay(transform.position, Bullet3_diagonal * length,Color.red);
if (Physics.Raycast(transform.position, Bullet1_diagonal,length)) {
Debug.Log ("Bullet 1 hit red!");
}
if (Physics.Raycast(transform.position, Bullet2_diagonal,length)) {
Debug.Log ("Bullet 2 hit red!");
}
if (Physics.Raycast(transform.position, Bullet3_diagonal,length)) {
Debug.Log ("Bullet 3 hit red!");
}
}
}
what i want to do it make it so what ever object the ray hits it returns the name of the object and destroys that object. for example im using it for a top down ish shooter game so the object it hits will be an enemy however there will be more then one of the same enemy in the scene at once so can you make it that what ever object the ray hits to destroy that singular ibect not every one of thoes object?
help would be awesome