I’m getting the following two errors and I’m not sure why.
NullReferenceException: Object reference not set to an instance of an object
Sugarrush.Update () (at Assets/Scripts/Sugarrush.cs:19)
NullReferenceException: Object reference not set to an instance of an object
Gamefunctions.Update () (at Assets/Scripts/Gamefunctions.cs:23)
using UnityEngine;
using System.Collections;
public class Sugarrush : MonoBehaviour {
public float rushbar = 60f;
float startTime;
TextMesh rushText;
// Use this for initialization
void Start () {
rushText = GetComponent<TextMesh>();
startTime = rushbar;
}
// Update is called once per frame
void Update () {
if (rushbar > 0f)
rushbar -= Time.deltaTime;
rushText.text = rushbar.ToString("0.0");
}
void OnGUI() {
//paramaters are position, width, height, title
GUI.Box(new Rect(10, 10, (Screen.width * (rushbar) / startTime) / 3, 20), "rushbar");
}
}
using UnityEngine;
using System.Collections;
public class Gamefunctions : MonoBehaviour {
// varable to use for accessing the sugarrush script
private Sugarrush srscript;
public float timer = 60f;
public float startTime;
private TextMesh timerText;
// Use this for initialization
void Start () {
srscript = gameObject.GetComponent<Sugarrush>();
timerText = GetComponent<TextMesh>();
startTime = timer;
}
// Update is called once per frame
void Update () {
if(srscript.rushbar <= 0){
Application.LoadLevel("death_Screen");
}
if (timer > 0f)
timer -= Time.deltaTime;
timerText.text = timer.ToString("0.0");
}
// inventory function array
//void CheckInvetory (){
// string[] inventory = new string[5] {
// "GumGun", "WaterPistol", "sleageHammer"
// };
// foreach(string items in inventory){
// Debug.Log(items);
// }
//}
void OnGUI() {
GUI.Box(new Rect(10, 10, (Screen.width * (startTime - timer) / startTime), 20), timer + "/" + startTime);
}
}