How will we enable and disable a gui texture in unity 3d?

Hi Every one,

I have a small task. That is very small task but there is i don’t know the error where it is.
By default my texture is on position. I want that into disable.

i wrote code like this:

var someTexture : Texture2D;

function Update () {

 if (Input.GetKeyDown ("space")){
    if (someTexture.enabled == true){
    someTexture.enabled = false;
    }
    else {
    someTexture.enabled = true;
    }
}
 }

My problem here is, I attached this script to main camera and added texture in the inspector of the main camera. After then play mode. Nothing will be getting in the game scene. what can i do? i want by default that texture is in show in game scene and if i press space button that will disable .and again i press space button i want to display.

please help me.
thankyou

You can declare the someTexture as a GameObject, and then use

someTexture.active = false; 

or

someTexture.SetActive(false);

since GameObject.SetActive is obsolete now.

The part where you actually place it is missing. You could try two different approaches:

Use the OnGUI() method to draw it into your viewport:

or transform the texture in your scene by using one of these two methods:

The first approach is easier to understand.

Here Is The Problem…
In place of Texture2D U need to put
GUITexture

var someTexture : GUITexture

I have same problem, and I discover this way is also fine

var showHPBar:GUITexture;
var MaxHP:int = 1000;
var HP:int = 500;

function Update(){
  showHP();
}

function showHP(){    

if(MaxHP != HP){
  showHPBar.gameObject.SetActive(true);
}
}

This is a tested project written in C# and working fine.

public GUITexture texture;
	
	void Update () {
	
		if(Input.GetKeyDown(KeyCode.Space))
		{
			if(texture.enabled == true)
				texture.enabled = false;
			else
				texture.enabled = true;
		}
	}