So here’s my dilema. I am trying to display a hat (The game object is called “Party” because it is a party hat) on my character by having the player click a button in a menu that sets the hat’s renderer to true. The hat is a child of my 2d character and the hat’s sprite renderer’s check box is unchecked (which I am assuming means that the renderer is false). When I run the game and click the button in the menu, Unity gives me an error saying “Object reference not set to an instance of an object” and the hat does not display in game. Here’s my script:
using UnityEngine;
using System.Collections;
public class HatSelectMenu : MonoBehaviour {
private GameObject party;
// Use this for initialization
void Start () {
party = GameObject.Find("Party");
}
// Update is called once per frame
void OnGUI () {
if(GUI.Button (new Rect(Screen.width / 2 - 50, Screen.height / 2 + 20, 200, 75), "Show Hat"))
{
party.renderer.enabled = true;
}
if(GUI.Button (new Rect(Screen.width / 2 - 30, Screen.height / 2, 100, 50), "Main Menu"))
{
Application.LoadLevel(0);
}
}
}
If you need any clarification I would be happy to help.