I am trying to set a GameObject active using a script which is not attached to the Object itself.
GameObject SpecificGame = GameObject.Find("GameT" + gameItemSlot);
SpecificGame.SetActive(true);
SpecificGame.GetComponent<gamesTabItem>().gameID = gameID;
Yes, the variables gameItemSlot
and gameID
are working fine.
The script is supposed to set the inactive GameObject "GameT1" active. I get the following error when I try it:
NullReferenceException: Object reference not set to an instance of an object
gamesTab.GenerateTabItem (Int32 gameID) (at Assets/Scripts/gamesTab.cs:104)
System.Collections.Generic.List`1[System.Int32].ForEach (System.Action`1 action) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:361)
gamesTab.UpdateLibrary () (at Assets/Scripts/gamesTab.cs:46)
moneyTime.UpdateDisplay () (at Assets/Scripts/moneyTime.cs:42)
moneyTime.Start () (at Assets/Scripts/moneyTime.cs:31)
As far as I understood the other questions and the documentation, the error says that SpecificGame is not set correctly. I am a Unity and C# noob, sorry for that :p