- Home /
Help! Hiding/showing GUITextures!
So I'm working on a game in Unity using javascript. My problem is I can't seem to figure out how to activate a GUITexture that is not attactched to the certain texture (External Script).
So here I have my script for my button which is called Upgrade.js
  var normalTexture : Texture;
  var hoverTexture : Texture;
  var pressedTexture : Texture;
  var messagee : GameObject;
  var message = "ButtonPressed";
  
  private var state = 0;
  private var myGUITexture : GUITexture;
  
  myGUITexture = GetComponent(GUITexture); 
  
  function OnMouseEnter()
  {
     state++;
     if (state == 1)
         myGUITexture.texture = hoverTexture;
  }
  
  function OnMouseDown()
  {  
      state++;
     if (state == 2)
         myGUITexture.texture = pressedTexture;
         
         var window = gameObject.Find("WindowUpgrade");
         
         if(window.active == false){
             window.setActive = true;
         }
  }
  
  function OnMouseUp()
  {
     if (state == 2)
     {
         state--;
         if (messagee)
             messagee.SendMessage(message, gameObject);
     }
     else
     {
         state --;
         if (state < 0)
             state = 0;
     }
     myGUITexture.texture = normalTexture;
  }
  
  function OnMouseExit()
  {
     if (state > 0)
         state--;
     if (state == 0)
         myGUITexture.texture = normalTexture;
  }
The problem is with the OnMouseDown function!
Here is the other script, CloseBox.js:
 #pragma strict
 
 function Update(){
     
     if (Input.GetKeyDown("c")){
         
         guiTexture.active = false;
     }
     
 }
The error I get is "NullReferenceException: object reference not set to an instance of an object"
Any help is much appreciated!
Thanks!
-Lucas Springsteen
Answer by robertbu · Dec 27, 2013 at 04:16 AM
Assume that your first script is attached to a game object with a unique name like "Upgrade" you can replace line 7 in the second script with:
 GameObject.Find("Upgrade").guiTexture.active = false;
If the game object has a unique tag, you can use FindWithTag() instead of Find().
Your answer
 
 
             Follow this Question
Related Questions
GUITexture KeyInput 1 Answer
GUITexture and GameObject OnMouseDown() Problem 1 Answer
How would I implement a GUI texture that acts as a slider? 0 Answers
GUI texture touch input problem 1 Answer
Unity GUI Style with if Statements 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                