Hi there!I’ve created a shot code here’s it:
function Update () {
if(Input.GetAxis("Fire1"))
{
shot();
}
}
function shot()
{
var up = transform.TransformDirection(Vector3.up);
var hit : RaycastHit;
Debug.DrawRay(transform.position, up * 10, Color.green);
if(Physics.Raycast(transform.position, up, hit, 10)){
Debug.Log("Hit");
if(hit.collider.gameObject.name == "enemy"){
Destroy(gameObject.Find("enemy"));
}
}
}
This code works pretty fine when I have only one enemy in screen but fails when I put 4 or + enemies,how can I do a code that destruct one enemy per time?