I am a total noob with unity and c# or please forgive me…
Ive got two assest I bought and I and trying to get them to talk to each other. 1) a sample completed game 2) a new ui
The error I am getting it “NullReferenceException: Object reference not set to an instance of an object” which i know means that it thinks I am calling a null.
Below is the UI Code trying to call Restart(); from LevelManager.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[ExecuteInEditMode()]
public class PauseManager : MonoBehaviour {
public LevelManager levelManager;
public PlayerManager playerManager;
public GUIManager guiManager;
public AudioManager audioManager;
public CameraManager cameraManager;
// Lots of other code between... //
//Draw replay button
if(GUI.Button(new Rect(maxButtonRight + Screen.width/8 - scaleWidth/2,Screen.height*4/10.0f,scaleWidth,scaleWidth),textures[1],"trans_button"))
{
isShow = false;
//------------------------------
//Do replay function in here
//-----------------------------
levelManager.Restart();
}
// Lots of other code between... //
Below is the Restart(); method in LevelManager.cs
//This is the main function for the level restart mechanic
public void Restart()
{
if (inRestart)
return;
inRestart = true;
//timeManager.Restart();
guiManager.Restart();
cameraManager.Restart();
gatheredCoins = 0;
for (int i = 0; i < coins.Length; i++)
coins*.SetActive(true);*
-
for (int j = 0; j < lifts.Length; j++)*
-
lifts[j].Reset();*
-
for (int k = 0; k < doors.Length; k++)*
-
doors[k].Restart();*
_ /* for (int n = 0; n < timeModifiers.Length; n++)_
_ timeModifiers[n].SetActive(true); */_
-
coinsToDisplay = "00/";*
-
if (coins.Length < 10)*
-
coinsToDisplay += "0" + coins.Length;*
-
else*
-
coinsToDisplay += coins.Length;*
-
guiManager.coins = coinsToDisplay;*
-
playerManager.Respawn();*
-
StartCoroutine(RestartOver());*
-
}*
According to these links this logic should work.
How do I call a function in another gameObject's script? - Questions & Answers - Unity Discussions
http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
What am I doing wrong here? There is something that I am missing. Because its not just an error with the LevelManager.cs but the new ui script also bugs on any reference to another script. So audioManager.PlayAudio(6); and cameraManager.DisableOrbit(); both give the same Null object error if I put them into the new ui script.