- Home /
NullReferenceException (really confused here.)
NullReferenceException: Object reference not set to an instance of an object CursorControl.Update () (at Assets/Scripts/CursorControl.cs:42)
I have been looking at this for the past few days and I can't seem to find out whats wrong. I don't even know if its this script that's the problem at this point but I looked at the others and they seem ok too.
using UnityEngine;
using System.Collections;
public class CursorControl : MonoBehaviour {
private GameObject multiplayerManager;
private MultiplayerScript multiScript;
private GameObject gameManager;
private CommunicationWindow commScript;
private ScoreTable scoreScript;
private GameSettings settingsScript;
void Start(){
if(networkView.isMine == true){
multiplayerManager = GameObject.Find("MultiplayerManager");
multiScript = multiplayerManager.GetComponent<MultiplayerScript>();
gameManager = GameObject.Find("GameManager");
commScript = gameManager.GetComponent<CommunicationWindow>();
scoreScript = gameManager.GetComponent<ScoreTable>();
settingsScript = gameManager.GetComponent<GameSettings>();
}
else{
enabled = false;
}
}
void Update(){
if(multiScript.showDisconnectWindow == false &&
commScript.unlockCursor == false &&
scoreScript.blueTeamHasWon == false &&
scoreScript.redTeamHasWon == false &&
settingsScript.showSettings == false){
Screen.lockCursor = true;
}
if(multiScript.showDisconnectWindow == true ||
commScript.unlockCursor == true ||
scoreScript.blueTeamHasWon == true ||
scoreScript.redTeamHasWon == true ||
settingsScript.showSettings == true){
Screen.lockCursor = false;
}
}
}
Does the game manager have the game settings script attached?
oh wow I must have removed the settings script by accident from the game manager. All is well again, thank you.
Answer by DaveA · Feb 07, 2014 at 09:29 AM
You are only setting these variables in Start if 'network is mine' If not, they'll all be null. Update is not checking if 'network is mine' so it's trying to access those non-initialized variables.
Your answer

Follow this Question
Related Questions
Null Reference Exception Help 1 Answer
Burgzerg arcade error with vital mods 0 Answers
how can i play soundclip by name? 1 Answer
Why do I get a null reference with this timer? 2 Answers
Null Ref Exeption 1 Answer