I am trying to make a tower defense game. At the moment i am trying to get the enemies to spawn. I can get them to spawn just find but the problem is that i cannot seem to change their name. This is my code:
private int spawnTime = 5;//seconds between enemies
private float timer = 0;//countdown
public Transform enemy;
void Start(){
timer = spawnTime;
}
void Update(){
if(timer>0){
timer -= Time.deltaTime * 2;
}else if(timer==0 || timer<0){
timer = spawnTime;
Spawn();
}
}
void Spawn(){
GameObject newEnemy = (GameObject)Instantiate(enemy, transform.position, Quaternion.identity);
newEnemy.name = "test";
//newEnemy.transform.position = new Vector3(0f, 0.5f, 0f);
}
Can anyone tell me how i can rename the instantiated GameObject?
EDIT:
After editing my code i found that nothing after,
GameObject newEnemy = (GameObject)Instantiate(enemy, transform.position, Quaternion.identity);
is “executing”.