GUITexture is not working (unreferencing itself?)

I have been trying to get the GUI texture on unity working (more specifically, changing the image), but every time I try to do so, it either does not want to work or it un-references itself (becoming “none” in the inspector). This also happens when I try to just drag and drop the reference into the inspector, but when I run it and press the input for it to work, it un-references itself as well, could it be something wrong with the logic? Here is what I have so far:

public class HUDTest : MonoBehaviour
{
	public GUITexture livesImage;
	public GUITexture tempTex;
	public int lives = 3;

	void Start()
	{
		livesImage = GameObject.Find("TestImage01").GetComponent<GUITexture>();
	}
	
	void Update()
	{
		//A simple test
		if(Input.GetKeyDown("0"))
		{
			lives++;
			livesImage = getNumberTexture(lives);
		}
	}

	GUITexture getNumberTexture (int number)
	{
		//Depending on the number recived...
		switch (number)
		{
		case 0:
			//If number 0 is selected, get the GUItexture 0
			tempTex = (GUITexture)Resources.Load("Num0", typeof(GUITexture));
			break;
		case 1:
			//If number 1 is selected, get the GUItexture 1
			tempTex = (GUITexture)Resources.Load("Num1", typeof(GUITexture));
			break;
		case 2:
			//If number 2 is selected, get the GUItexture 2
			tempTex = (GUITexture)Resources.Load("Num2", typeof(GUITexture));
			break;
		case 3:
			//If number 3 is selected, get the GUItexture 3
			tempTex = (GUITexture)Resources.Load("Num3", typeof(GUITexture));
			break;
		case 4:
			//If number 4 is selected, get the GUItexture 4
			tempTex = (GUITexture)Resources.Load("Num4", typeof(GUITexture));
			break;
		case 5:
			//If number 5 is selected, get the GUItexture 5
			tempTex = (GUITexture)Resources.Load("Num5", typeof(GUITexture));
			break;
		case 6:
			//If number 6 is selected, get the GUItexture 6
			tempTex = (GUITexture)Resources.Load("Num6", typeof(GUITexture));
			break;
		case 7:
			//If number 7 is selected, get the GUItexture 7
			tempTex = (GUITexture)Resources.Load("Num7", typeof(GUITexture));
			break;
		case 8:
			//If number 8 is selected, get the GUItexture 8
			tempTex = (GUITexture)Resources.Load("Num8", typeof(GUITexture));
			break;
		case 9:
			//If number 9 is selected, get the GUItexture 9
			tempTex = (GUITexture)Resources.Load("Num9", typeof(GUITexture));
			break;
		default:
			//If it is not a number, return a "0"
			tempTex = (GUITexture)Resources.Load("Num0", typeof(GUITexture));
			break;
		}

		return tempTex;
	}
}

This is a lives example I written up, all it is supposed to do is change a GUITexture when the lives number changes. What am I doing wrong and what can I do to fix this problem?

The livesImage field would get set to null, if Resources.Load returned null. This would happen if Num0 - Num9 were not GUITexture prefabs stored inside a Resources folder.

Anyway, let’s say that Num0 - Num9 are just image files, e.g. Num0.png to Num9.png. You don’t need the getNumberTexture method to accomplish what you need. You just need to store your images in an array, and then set the GUITexture.texure property to the correct image.

Try the following:

    //Create an array to hold the images that will be used in the GUITexture
    //Drag and drop image files in the inspector
    public Texture2D[] LifeCountTexures = new Texture2D[10];
	
	// Update is called once per frame
	void Update () {

        //A simple test
        if (Input.GetKeyDown("0"))
        {
            lives++;
            livesImage.texture = LifeCountTexures[lives];  //just set the texture property of GUITexture
        }
	}