- Home /
Variable disappears in playmode?
Hey Unity Answers community,
Here's my script at the moment:
#pragma strict
var other : GameObject;
var buttons : GameObject[];
private var randNumber: int;
function Start () {
other.SetActive(true);
for (var i = 0; i < buttons.Length; i++)
buttons[i].SetActive(false);
InvokeRepeating("SwitchButtons", 0.0, 5.0);
}
function SwitchButtons() {
for (var i = 0; i < buttons.Length; i++)
buttons[i].SetActive(false);
randNumber = Random.Range(0,buttons.Length);
buttons[randNumber].SetActive(true);
}
function Update () {
if(buttons[0])
{
if(Input.GetKeyDown("q"));
other.transform.Translate(Vector3(2,0,0));
}
}
The issue is my variable (other) disappears once I go into play mode even though in inspector it's right where I want it. What's the issue?
Comment
Best Answer
Answer by AmoralAckbar · Jun 12, 2013 at 07:44 PM
In the Start function, you are setting the object to be inactive. That will make it disappear.
That would make it vanish from the Scene/Game window, and greys it out in the Hierarchy panel, but the variable itself shouldn't vanish.
What do you mean the variable is vanishing? From where?