- Home /
Changing texture for pause button
I am trying to changing the texture for a button when click pause/resume game.
The error is "UnassignedReferenceException: The variable button of PauseButton has not been assigned. You probably need to assign the button variable of the PauseButton script in the inspector. PauseButton.OnMouseDown () (at Assets/Scripts/PauseButton.cs:28) UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)"
The same apply to line 32 (when click the pause button again).
The code is following
using UnityEngine;
using System.Collections;
public class PauseButton : MonoBehaviour {
public static bool pauseGame = false;
public static bool pauseButtonClick = false;
public static Animator animator;
private Texture2D play;
private Texture2D pause;
public GUITexture button;
void Start ()
{
animator = GetComponent<Animator>();
Texture play = Resources.Load("playbutton") as Texture2D;
Texture pause = Resources.Load("pausebutton") as Texture2D;
}
void OnMouseDown()
{
animator.SetBool( "pauseButtonClick", true);
Invoke ("EndPauseButtonAnimation", .2f);
pauseGame =!pauseGame;
if(pauseGame)
{
button.guiTexture.texture = play;
}
else
{
button.guiTexture.texture = pause;
}
}
void EndPauseButtonAnimation()
{
animator.SetBool( "pauseButtonClick", false);
}
Answer by gjf · Mar 02, 2015 at 11:24 AM
lines 17 & 18 are your problem.
you're assigning a local variable within Start()
and not to the private fields that you really need. remove Texture
from each and it'll probably work...
Well, it worked. It took so much time of $$anonymous$$e. Just another lesson to be learnt.
Your answer
Follow this Question
Related Questions
Change texture of GUItexture from script 4 Answers
GUI_TEXTURE PROBLEM! 2 Answers
Floating Health Bars 1 Answer
Scaling bg gui texture without stretching it in unity 4.6 0 Answers