There's an issue with this script I can't find
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SetPrice : MonoBehaviour {
public Text me;
Tower[] towers;
Tower selected = null;
int cost = 75;
// Use this for initialization
void Awake ()
{
}
// Update is called once per frame
void Update ()
{
towers = GameObject.FindObjectsOfType<Tower>();
selected = null;
foreach (Tower t in towers)
{
if (t.selected)
{
selected = t;
}
}
if(selected != null)
{
cost = selected.money;
}
else
{
cost = 0;
}
Debug.Log(me.name);
}
}
I have this script attached to a game object in my game. In the inspector the public Text is set, and the debug.log at the bottom prints out the name of the object. However, I'm getting a null reference at the Debug.Log(me.name); line. I can't figure this out, and I've been trying for hours, please help.
It would not log out anything if 'me' was null and if it wasn't null, you wouldn't get an exception.
Since both happen, you must have one instance of this script with 'me' assigned in inspector and another one somewhere without 'me' assigned in inspector.
Your answer
Follow this Question
Related Questions
Input.GetButtonDown("left ctrl") dont work 1 Answer
Setting button intractability causes an error 1 Answer
Random Chance NullReferenceException: Object reference not set to an instance of an object 2 Answers
NullReferenceException: Object reference not set to an instance of an object error ? 1 Answer