• 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 /
avatar image
0
Question by Radon · Jul 12, 2012 at 03:23 AM · gui

Remove GUI Texture

Hello, I want a code that when I Right Click on my mouse and keep pressing it, it removes the GUI Texture. But when I stop pressing Right click, it will appear again. Thank you.

Comment
Add comment · Show 2
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
avatar image Chimera3D · Jul 12, 2012 at 03:59 AM 0
Share

First of all by "keep pressing it" do you mean hold the right mouse button down? Secondly what are you clicking to make this GUI texture disappear?

avatar image Radon · Jul 12, 2012 at 05:53 AM 0
Share

Yes, I mean hold and keep holding it down. I just want it to disappear when I stop pressing the right click.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Chimera3D · Jul 12, 2012 at 04:09 AM

If by "keep pressing it" you mean hold it down then this should work. First you will have to "get" the GUI texture game object. To do this create a variable and then use GameObject.Find to get it.

 var guiTexture : GameObject;
 
 function Start() {
 
      guiTexture = GameObject.Find //(name of gui texture object); Keep the name in parentheses and with a semicolon afterwards
 
 }

Then add the controls.

 function Update() {
 
     if(Input.GetMouseButton(1)){

          guiTexture.active = false;

     }else

          guiTexture.active = true;

     }

Note whenever the right mouse key isn't being pressed then the object will still show.

Comment
Add comment · Show 3 · 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
avatar image Radon · Jul 12, 2012 at 05:30 AM 0
Share

Ok so I went to GameObject > Create Other > GUI Texture, and named it Crosshair. Then I used your code like this

var guiTexture : GameObject;

function Start() {

  guiTexture = GameObject.Find(Crosshair);

}

function Update() {

 if(Input.Get$$anonymous$$ouseButton(1)){

 guiTexture.active = false;

 }
 else

  guiTexture.active = true;

}

Now I have 3 errors

BCE0004 - Line 13 BCE0005 - Line 5 BCE0004 - Line 17

avatar image Chimera3D · Jul 12, 2012 at 09:00 AM 0
Share

Crosshair should be formatted "Crosshair" exactly like that. Also change the guiTexture variable name itself to something else and you should be fine.

avatar image Radon · Jul 12, 2012 at 07:32 PM 0
Share

Thank you so much. That worked.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

How do I toggle the active state of a canvas UI object 0 Answers

GUI.DragWindow() Refuses to work 1 Answer

Skinned/unskinned GUI controls size differences 3 Answers

Can EditorWindows dynamically display interfaces of other Editor Windows ? 1 Answer

How to display Gui for clips left - FPS tutorial 0 Answers


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