Thursday, February 3, 2011

2.add and destroy GameObjects using "Tag" ......


hey guys,
1. ADD TAGS TO THE GAMEOBJECT:

dont add tag when create instantiate...the alternative way is better...you may change the existing tag instead for that...by example consider your prefab tag name as "man"...
assume if you want to instantiate 5 man and you want to tag it as "man1,man2,....man5" means you may do the script like this,
 
int k =1;
for(int j=1; j<=5; j++)
{
GameObject clone=Instantiate(prefab,someObject.transform
.position,Quaternion.identity) as GameObject; 

clone.transform.tag = "man"+k;
k++;
}
its very simple....here the tag name will be assigned......

2.Destroy using Tag Name:

 its simple to destroy it.....
Destroy(GameObject.FindWithTag(something.tag));


No comments:

Post a Comment