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 /
avatar image
0
Question by swimfly706 · Oct 09, 2013 at 10:43 PM · onmousedownclick objects

Popup Textures for game objects

I'm trying to design something where you can click on a game object and an image pops up, but then you can click an arrow and go to the next image, all in one click on the game object. I have this code which pops up a single image, but I want to incorporate more. Any help is appreciated!

var popupTexture : Texture2D; private var paperPopup : PaperPopup;

function Start () { paperPopup = FindObjectOfType(PaperPopup);

 if (popupTexture == null) {
     popupTexture = renderer.material.mainTexture;   
 }

}

function OnMouseDown () { paperPopup.Show(this); }

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 Cherno · Oct 09, 2013 at 11:20 PM

Sounds pretty simple :)

All you have to do is set a boolean to true if you click on the object, and then inside OnGUI() make your textures, buttons etc. appear if the boolean is set to true.

Comment
Add comment · Show 2 · 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 swimfly706 · Oct 10, 2013 at 12:54 AM 0
Share

Thanks for the help! I'm really new to Unity, so I'm not sure what you mean by how to make my textures, etc. appear if the boolean is true. Can you give me more specifics?

avatar image Cherno · Oct 13, 2013 at 02:27 AM 0
Share

Here is a comprehensive example.

 //Declare variables
 var ShowButtons : boolean;
 var Image1 : Texture2D;//Drag an image from the project view here.
 
 function Update()
 {
     var ray = Camera.main.camera.ScreenPointToRay (Input.mousePosition);//declares that our ray will go out from the main camera straight forward towards the screen
     var hit : RaycastHit;//stores information about things we hit with our ray
     
     if(Input.GetButtonDown("Fire1"))//Fire1 = Left mouse button (by default)
     {
         if (Physics.Raycast (ray, hit, $$anonymous$$athf.Infinity))//draws our ray, stored information about anything the ray hits in "hit", and goes on infinitely
         {
             ShowButtons = true;
         }
         else
         {
             ShowButtons = false;
         }
     }
 }
 
 function OnGUI()//the function where all GUI stuff is hapening. Similar to Update() in that it is called constantly, but unlike Update(), it is called multiple times per frame so drawn images don't flicker
 {
     if(ShowButtons == true)
     {
         GUI.DrawTexture (Rect(100, 100, Image1.width, Image1.height), Image1);//draw our image1
         
         var ButtonZone1 : Rect = new Rect(100, 100 + Image1.height, 50, 50);//declare where our button1 is and how big it is
     
         if (GUI.Button(ButtonZone1,"Button Zone 1"))//if a button that has the position and dimension of our ButtonZone1 Rectangle variable is clicked...
         {
             if (Event.current.button == 0)//...and the mouse button is the left one (0 = left, 1 = right, 2 = middle)
             {
                 Debug.Log("Clicked Button 1");//... then print a message in the console.
             }
         }
         
         var ButtonZone2 : Rect = new Rect(150, 100 + Image1.height, 50, 50);
     
         if (GUI.Button(ButtonZone2,"Button Zone 2"))
         {
             if (Event.current.button == 0)
             {
                 Debug.Log("Clicked Button 2");
             }
         }
     }
 }

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

16 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

Related Questions

How to change texture of another object by clicking on a object? 0 Answers

How can I change the texture of a game object by clicking on another game object? 1 Answer

OnDestroy collision detect 4 Answers

Stop a Lerp from looping 3 Answers

OnMouseUp error 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