So I'm creating a game in which the player has several playing pieces to choose from. I've created a game manager which is a singleton (and I think that might be part of my problem). The pieces are Unity UI buttons, and when they are clicked a script on the Manger is called which stores which piece was clicked on. If another piece was already selected, I want to forget about the piece and as a visual cue to the player I'm adjusting the scale. So here's my code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Manager : MonoBehaviour {
public static Manager manager;
GameObject chosenPiece = null;
void Awake()
{
if (manager == null)
{
//DontDestroyOnLoad(gameObject);
manager = this;
} else if (this != manager)
{
Destroy(gameObject);
}
}
public void PieceClicked(GameObject thisPiece)
{
Vector3 scaleFactor = new Vector3(0.1F, 0, 0.1F);
if (chosenPiece != null)
{
chosenPiece.transform.localScale -= scaleFactor;
}
thisPiece = chosenPiece;
chosenPiece.transform.localScale += scaleFactor;
}
Trouble is when I run it, I get this error
> UnassignedReferenceException: The> variable chosenRune of Manager has not> been assigned. You probably need to> assign the chosenRune variable of the> Manager script in the inspector.
I also tried changing around my if statement so that it was if (chosePiece == null) and even tried if(chosenPiece == null || chosenPiece.Equals(null)) but I got the same errors that way.
Most people who have similar error seem to have an issue with the script being attached to multiple objects. I've gone through and double checked, and there is only one version of the Manager Script in the scene once I've hit play (before as well). So why can't I check if my chosenPiece is null?
↧