Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by $$anonymous$$ · Dec 27, 2013 at 03:09 AM · guiinputguitextureif-statements

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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().

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges