NullReferenceException: Object reference not set to an instance of an object
GameOverResults.OnGUI () (at Assets/Scripts/GameOverResults.cs:12)
public class GameOverResults : MonoBehaviour {
public void OnGUI() {
//find score variablen fra handattack
GameObject eHand = GameObject.Find ("Hand");
handAttack gHand = eHand.GetComponent<handAttack> ();
string FinalScore = string.Format("{0}", gHand.theScore);
//find time variablen fra guitimer
GameObject eTime = GameObject.Find ("Plate");
guiTimer gTime = eTime.GetComponent<guiTimer> ();
string Finalminutes = Mathf.Floor(gTime.timer / 60).ToString("00");
string Finalseconds = Mathf.Floor(gTime.timer % 60).ToString("00");
string FinalTime = string.Format("Tid {0:0}:{1:00}", Finalminutes, Finalseconds);
GUI.Label(new Rect(595, 8, 20, 20), FinalScore);
GUI.Label(new Rect(605, 8, 20, 20), FinalTime);
}
}
use Debug.Log to find the missing component. It can be everything that you retrieve from GameObject.Find or GetComponent. i.e. eHand, gHand, eTime, gTime. What exactly is line 12 in your script? The error occurs there.
– HrungdakI think eTime is null, the GameObject "Plate" has not been found in your scene (you should test eTime value before doing operations on it).
– Nerevarcould it be because the things I want to get are in another scene?
– FanihaYes, it is because it is not in the scene.
– fafase[46640-facepalm.jpg|46640] ^^ You cannot access objects that are not in your scene .
– Nerevar