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));


Wednesday, February 2, 2011

1.Find the Parent Object name using child in unity3d

if you want to get the parent object name means,

Assume,your parent object name as, Man....it have child name as hand...

GameObject ParentName = GameObject.Find("hand").transform.parent.gameObject;
Debug.Log("parent name :  "+ParentName.name);

it'll give your parent Object name as man....it'll really helpful when you find objects name in runtime.