Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by mrhctran · Oct 25, 2015 at 05:11 PM · guigameobjectguitexturehide

Remove or Add Blank Images to GUI.DrawTexture in Unity 3D

I got my code to work correctly but I can't seem to remove GUI.DrawTexture if on press on another GUI button that not on the previous or next button. How can I remove the texture or add a blank texture to the GUI.DrawTexture once I press the 3D Model Gui button?

 #pragma strict 
 var images : Texture2D[]; 
 var i : int = 0;
 public var objectToHide:GameObject;
         
         function OnGUI () {
         
             GUI.DrawTexture(Rect(365,20,1500,900),images[i]);
         
             if (GUI.Button(new Rect(880,930,100,50),"PREVIOUS"))
             {
                 if (i > 0)
                     i--;
         
                 GUI.DrawTexture(Rect(200,50,100,100), images[i]);
                 print(i);  
         
                 objectToHide.SetActive(false);
             }
         
             if (GUI.Button(new Rect(1000,930,100,50),"NEXT"))
             {
                 if (i < images.Length - 1)
                     i++;
         
                 GUI.DrawTexture(Rect(200,50,100,100), images[i]);  
                 print(i);
         
                 objectToHide.SetActive(false);
             }
         
             if (GUI.Button(new Rect(1120,930,100,50),"3D MODEL"))
         
             {
                 objectToHide.SetActive(true);    
             }  
      }
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
Best Answer

Answer by Statement · Oct 25, 2015 at 05:33 PM

Keep state of your behaviour.

 var showImage = true;

And if showImage is true, display the texture...

          if (showImage)
              GUI.DrawTexture(Rect(365,20,1500,900),images[i]);

If we click 3D model, hide the texture.

          if (GUI.Button(new Rect(1120,930,100,50),"3D MODEL"))         
          {
              showImage = false; // set a boolean
              objectToHide.SetActive(true);    
          } 

I've got some experience with Unitys IMGUI and I can tell you it'll get boring pretty quickly if you don't make an object model wrapper around IMGUI calls because you'll end up juggling so many state variables and cook up a nice bowl of ramen code.

But now that Unity has a new UI system, why are you using the old system? You don't appear to be writing editor extensions.

Comment
Add comment · Show 1 · 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 mrhctran · Oct 25, 2015 at 07:32 PM 0
Share

Thanks you! That really worked! Originally, I have it working with Unity new UI system, but I couldn't apply the next-previous images without the hard coding. I didn't know how to setup a next - previous in the new UI system.

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

45 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use individual textures as font in GUI? 0 Answers

"There is no CharacterController attached to the "example" game object, but a script is trying to access it. Error please help 0 Answers

Create a UI and place onto object 1 Answer

How to create GUI BUTTON from this 1 Answer

Assertion failed on expression: 'device.IsInsideFrame()' 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