- Home /
 
               Question by 
               xKroniK13x · Jul 04, 2012 at 05:18 AM · 
                transformprefabpositionspawn  
              
 
              Setting Position of Spawned Prefab
Hey guys, I thought this would be relatively simple, but can't seem to grasp it.
I have:
     if (GUI.Button (Rect (Screen.width/2-50, 125, 100, 30), "Floor")) {
  var instance : GameObject = Instantiate(Resources.Load("Floor", GameObject));
 }
and tried
 instance.transform.position = positionvariable;
and that did not work. Any ideas? I tried finding online but got nothing! Thanks ahead of time!
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by purdyjo · Jul 04, 2012 at 05:40 AM
Yeah that should work perfectly fine. This shouldn't make a difference but try setting the position when you instantiate it via
 Instantiate(Resources.Load("Floor", GameObject), positionvariable, Quaternion.Identity);
Answer by Kryptos · Jul 04, 2012 at 07:52 AM
Your variable instance is declared inside the if-statement. Therefore, it is not available outside its scope.
At least that's how it works with C#, I'm not sure whether the behaviour is the same with UnityScript.
Your answer
 
 
             Follow this Question
Related Questions
How can I translate my prefab on Instantiate? 1 Answer
Prefab Transform variable missing. 1 Answer
Checking Position 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                