Hello
I am trying to make a simple menu script that goes to the level picked and changes the material of a game object. Do this I have created five scripts.
Here is the code for the first one
#pragma strict
var Level_Select : int;
function Start () {
}
function Update () {
if (Input.GetKey ("up"))
{
Level_Select--;
Debug.Log (Level_Select);
}
if (Input.GetKey ("down"))
{
Level_Select++;
Debug.Log (Level_Select);
}
if (Level_Select == 1)
{
renderer.material.color = Color.grey;
}
else
{
renderer.material.color = Color.black;
}
}
Then in the other scripts the code is
#pragma strict
function Start () {
}
function Update () {
if (Input.GetKey ("up"))
{
Main_Menu_Script.Level_Select--;
Debug.Log (Main_Menu_Script.Level_Select);
}
if (Input.GetKey ("down"))
{
Main_Menu_Script.Level_Select++;
Debug.Log (Main_Menu_Script.Level_Select);
}
if (Main_Menu_Script.Level_Select == 2)
{
renderer.material.color = Color.grey;
}
else
{
renderer.material.color = Color.black;
}
}
Then the other 3 scripts are similar to the last one just with “Level_Select” being a different number. I haven’t added the code to change the level yet.
When the Level_Select variable isnt static I get the error “Assets/Scripts/Main Menu/Main_Menu_Script_2.js(21,38): BCE0020: An instance of type ‘Main_Menu_Script’ is required to access non static member ‘Level_Select’.” When I change the Level_Select variable to a static variable all the errors go away. So my question is, is it possible to access a non static variable in another script and if it is possible, how.
Thank You