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);
	}

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…