private int mapSelected;
private mainmenu mainMenu;
void Awake() { mainMenu =
GetComponent(); }void Start() { mapSelected =
mainMenu.champSelected; }
Object reference not set to an instance of an object
introbeforegame.Start ()
what’s wrong?
private int mapSelected;
private mainmenu mainMenu;
void Awake() { mainMenu =
GetComponent(); }void Start() { mapSelected =
mainMenu.champSelected; }
Object reference not set to an instance of an object
introbeforegame.Start ()
what’s wrong?
You need to supply a type to GetComponent. See the documentation.
If the component you want is a script you have created, use that as the type parameter.
e.g. If you named a script “MenuScript”:
mainMenu = GetComponent(MenuScript); // JS
mainMenu = GetComponent<MenuScript>(); // C#
Script 1:
if (GUI.Button (new Rect (10,175, 220,40), "option1", GUI.skin.GetStyle("button")))
{
champSelected = 4;
Application.LoadLevel ("Harborintro");
}
if (GUI.Button (new Rect (10,175, 220,40), "option2", GUI.skin.GetStyle("button")))
{
champSelected = 4;
Application.LoadLevel ("Harborintro");
}
Script nr2
Load champSelected from script 1 and save it in “mapSelected”