- Home /
static gameobject
i have a script on one object, the script is called "Manager"
static var share : GameObject;
var obj : GameObject
function Update () {
share = obj
}
then another script on another object to instantiate.
var object : GameObject;
var spawn = Instantiate(object ,Manager.share.transform.position,Quaternion.identity);
object.transform.parent = Manager.share.transform;
but it doesn't seem to work :/ any ideas? thanks
i'll add the object with the second script is instantiated at runtime itself and the "share" object is in the scene from the start as is the object containing the first script
thanks
check for null '$$anonymous$$anager.share' before instantiating.
and... what does it mean - 'doesn't see to work'?
how are you calling the Instantiate? is that inside a function?
The relationship between a static property which is a gameObject is a non trivial matter, I wrote some extended notes here.
Answer by fafase · Jul 29, 2012 at 05:36 PM
A static game object? Just search and find the object. Here I assume the GO is named Share:
var object : GameObject;
var share:Transform;
function Start(){
share = GameObject.Find("Share").transform;
}
var spawn = Instantiate(object ,share.transform.position,Quaternion.identity);
object.transform.parent = share.transform;
Your answer
Follow this Question
Related Questions
Get the Vector position of the player object when clicking another object C# 1 Answer
How to make random alien fire and not all of them at once.. 2 Answers
Set parent of instantiated object. 0 Answers
How to instanciate transform to element of a list?,How Get Transform of a instanciated Prefap 3 Answers
problems parenting a gameObject to another upon instantiating when same name exists 1 Answer