GUI.DrawTexture and assign it to a variable?

Hi guys,
I’m just trying to show a health bar in a fixed screen coordinate, but to manipulate the health bar I need to assign it to a variable.
I’m drawing the bar with GUI.DrawTexture, and the problem is that I’m trying to assign it to a variable for hour with no sucess.
I ever get this error: Cannot implicitly convert type ‘void’ to `UnityEngine.GUITexture’.

I think that the problem here is the variable type that I’m using, but I was unable to find the proper type.

Here’s a little bit of my code:


    public Texture2D healthSpr;
	public Texture2D healthbarSpr;
	public Color healthColor;

	private GUITexture healthUI;

	void OnGUI()
	{
		GUI.DrawTexture (new Rect (50, 15, 500, 100), healthSpr);
		healthUI = GUI.DrawTexture (new Rect (50, 15, 500, 100), healthbarSpr);
	}

I only need to assign the second GUI.DrawTexture to the healthUI variable. Any help will be appreciated.

Thanks in advance.

GUI.DrawTexture is a method that is used to draw a texture on OnGUI. It’s return type is void and because of that you can’t assign it’s return value to a variable, as you are trying to do.

You will have to store the actual values used to create the DrawTexture and modify those instead.