- Home /
Question by
undead504 · May 14, 2017 at 05:03 PM ·
javascriptgameobjectinstantiatetransform.position
hello there I am Trying to Instantiate a 1 of 5 GameObjects
Hello there I have 5 Rooms and I need 1 of the 5 Rooms to Instantiate and Spawn. I can Instantiate the Rooms but I cant tell it to make it random. here is what i have so far.
var NBR = Random.Range(1,6);
var room1 : GameObject;
var room2 : GameObject;
function OnTriggerExit(){
if(NBR==1){
room1.transform.position.z = GameObj.transform.position.z +11;
}
if(NBR==2){
room2.transform.position.z = GameObj.transform.position.z +11;
}
}
any Help would be Very much appreciated And Thank you.
Comment
Not sure what you're doing, but if you want a random number, it should not be declared in the field initializer.
Something like
function OnTriggerExit()'
{
NBR = Random.Range(1, 6);
if(NBR==1)
{
room1.transform.position.z = GameObj.transform.position.z +11;
}
if(NBR==2)
{
room2.transform.position.z = GameObj.transform.position.z +11;
}
}
Your answer
Follow this Question
Related Questions
Instantiate as a child at position 2 Answers
GameObject change Position after game started 1 Answer
swap objects with instantiate 2 Answers
[SOLVED] Only instantiating once 1 Answer