I am new to unity and working on FPS game, What i am doing right now if my main character is entering a new room randomly enemy will be created in range 1-4 , suppose 3 enemy created in new room. Iam using prefab for enemy generation and generating it using Instantiate function.
Now the problem so after Instantiating function call in my hierarchy enemy will be created with name enemy(clone), i want to do something like if 5 bullets hit the enemy it will destroy so in OnCollisionEnter() i am calling hitCheck function and as soon as hit count increase 5 all my enemy(clone) will destroy. Here is my OnCollisionEnter function.
function OnCollisionEnter(col:Collision)
{
print(col.gameObject.name);
if(col.gameObject.name == "Enemy(Clone)")
{
col.gameObject.GetComponent(EnemyAI).hitCheck();
}
Destroy(gameObject);
}
and here is my hitCheck() function
function hitCheck()
{
hit++;
var cposition:Vector3;//get current position of enemy so that we can place blood at that position
cposition = Vector3(transform.position.x,transform.position.y,transform.position.z);
Instantiate(blood,cposition,Quaternion.identity);
if(hit>4)
{
Destroy(gameObject);
}
}
I want to know best way to generate enemy and how to control them.