- Home /
Change Name Of Prefab That Initiates
Hello,
I have an enemy spawn that spawns enemies every so often. They are initiated from a prefab, and when they do initiate, they are called Enemy(clone). Is it possible to give each enemy that is spawned a unique ID.
So far I have got this:
function Start ()
{
transform.name = ("EnemySpawned");
}
Which simply changes the name of all the Enemies that initiate, to EnemySpawned. I'm not very good to codes arrays, but I want it so it will be like:
EnemySpawned1
EnemySpawned2
EnemySpawned3 .... (you get the idea)
So every enemy that does spawn adds an extra value to its endding name
Answer by denewbie · Nov 18, 2010 at 04:35 PM
int prefebIndex = 0;
function spawnEnemy() { var Enemy:GameObject = Instantiate(myPrefab); Enemy.transform.name = "EnemySpawned" + prefebIndex; prefebIndex++; }
$$anonymous$$ine starts from zero tough... You can start from one by changing the line "int prefebIndex = 0; " to "int prefebIndex = 1; "
Thanks Denewbie, you have answered a LOT of my questions. Thanks!
Your answer
Follow this Question
Related Questions
Change Character Controller Collider - to another Collider? (*CCCC+Quest*) 1 Answer
How do I change my speed based on certain events? 0 Answers
How to change part of complex gameobject instantiated from prefab? 1 Answer
SetCursor WebGL doesn't work 1 Answer
change scene on click of a 3d object 1 Answer