Question by
SamCarey · Apr 24, 2016 at 02:51 AM ·
javascriptgameobjectarraysetactivehealth
Set Active Random GameObject from array (JavaScript)
I have an array of GameObjects. When the game starts, I want a script that will randomly choose one of the objects in the array and set it as active. This need to be in JavaScript.
Comment
Best Answer
Answer by SamCarey · Apr 25, 2016 at 12:33 AM
Just worked it out myself.
var RanItem = 0;
var Items : GameObject[];
var Item : GameObject;
function Start ()
{
RanItem = Random.Range(0,Items.length);
Item = Items[RanItem];
Item.SetActive(true);
}
Your answer
Follow this Question
Related Questions
How to enabled a specific gameObject in array? 0 Answers
How to make a GUI bar that counts items collected 0 Answers
How to keep bool true even when other method try to set it off 0 Answers
gameObject.SetActive (false); Not working 0 Answers
How can I deactivate a GameObject's Child (Gun) however keep the parent (the player) active? 1 Answer