- Home /
How to access an instantiated game object using c# ?
hey there ,,, im trying to instantiate a Cylinder which is already in my assets as a prefab , then after its instantiated , i want to scale the clone , so i tried using an script attached on my Main Camera ,,, that part of the script for instantiating is like this :
Public Transform Circle;
...
public void instantiator (float radius , Vector3 Pos)
{
GameObject IC = GameObject.Instantiate(Circle,Pos,transform.Rotation) as GameObject;
if(IC != null)
IC.transform.localScale = new Vector3(radius , radius , 0f);
else
Debug.Log("there is nothing instantiated");
}
... and when i instantiate it , it acts like there is nothing in the IC so it shows the message on console "there is nothing instantiated" ... is there a way to solve it , or , is there any way to access the instantiated GameObject ,,, i searched alot about it but none of those offered ways worked for me :(
Answer by Kos-Dvornik · Jul 09, 2012 at 11:48 AM
Try this one:
Transform IC = GameObject.Instantiate(Circle,Pos,transform.Rotation) as Transform;
After that you can acess gameObject as IC.gameObject