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 GorandomStudios · May 20, 2014 at 12:31 PM · c#textureguitextureonclickpopup

Activating a GUITexture by clicking on an object (script in c#)?

Hi everyone,

I am new in coding and unity in general. I am working on a simulation, scripted in c#, and I want that the player is able to click on an object and get more information about that object in a popup. The popup must consist of a PNG(homemade (name: clickonme)) and a cross in a small box(generated by Unity) to exit the popup. In this picture (see attachments if this is too small to read)

alt text

you can see the errors that Unity indicates (MonoDevelop says that there are no errors), I have obviously done something wrong and I think that the thing that goes wrong is me not knowing how to tell Unity which file(the PNG) to use. (I really don't know how to formulate this better sorry)

So if someone knows how to correct this that would be great!

Thanks for replying and you can always ask me if I forgot some information!

This is my code:

 using UnityEngine;
 using System.Collections;
 
 public class onclickGUI : MonoBehaviour {
     
     // Use this for initialization
     private bool PopUp;
     public string Info;
     public GUITexture clickonme;
 
     void OnMouseDown()
     {
         PopUp = true;
     }
     
     void DrawInfo()
     {
         if(!clickonme)
         {
             Debug.LogError (clickonme);
             return;
         }
         GUI.DrawTexture(Rect(50,50,250,250), clickonme, ScaleMode.ScaleToFit, true, 10.0f);
         Rect close = new Rect (250,50,50,50);
         if (PopUp)
         {
             GUI.Box(Rect, Info);
             if (GUI.Button (close,"X"))
             {
                 PopUp = false;
             }
         }
     }
     void OnGUI()
     {
         DrawInfo();
     }
 }


unityforum1.jpg (127.6 kB)
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

2 Replies

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

Answer by Landern · May 20, 2014 at 12:38 PM

Not sure how MonoDevelop didn't throw an error due to using a Rect type wrong in GUI.DrawTexture.

I don't know what size & position you wanted for the Info Box, so i made up some values in the new Rect. DrawTexture takes a Texture type, not a GUITexture, you were missing the new keyword on line:23.

Here you go, modify as needed:

 using UnityEngine;
 using System.Collections;
 
 public class onclickGUI : MonoBehaviour {
     
     // Use this for initialization
     private bool PopUp;
     public string Info;
     public Texture clickonme;
     
     void OnMouseDown()
     {
         PopUp = true;
     }
     
     void DrawInfo()
     {
         if(!clickonme)
         {
             Debug.LogError (clickonme);
             return;
         }
         GUI.DrawTexture(new Rect(50,50,250,250), clickonme, ScaleMode.ScaleToFit, true, 10.0f);
         Rect close = new Rect (250,50,50,50);
         if (PopUp)
         {
             GUI.Box(new Rect(100, 50, 100, 50), Info);
             if (GUI.Button (close,"X"))
             {
                 PopUp = false;
             }
         }
     }
     void OnGUI()
     {
         DrawInfo();
     }
 }
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 GorandomStudios · May 20, 2014 at 01:25 PM 0
Share

Thank you for the quick reply! The errors are gone, but now the texture is always on and I want it to only show once you click on the object, however the "X" button is only appearing when you click on the object and disapearing when you click the "X" button. Do you know why the GUI.box is doing what I want and the GUI.DrawTexture not? Is the GUI.DrawTexture simply misplaced or is it something else? (if you think it's stupid of me to ask everything you can say that ;) )

avatar image GorandomStudios · May 20, 2014 at 01:30 PM 0
Share

Ow! Is it just that i forgot to put

 if (PopUp)

above line 18?

avatar image
0

Answer by Sisso · May 20, 2014 at 12:39 PM

You need to fix all this script errors indicated by unity3d before run your scene. For each error ready carefully, look the code, search in the internet, change and fix.

http://unity3d.com/learn/tutorials/modules/beginner/scripting

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 GorandomStudios · May 20, 2014 at 01:26 PM 0
Share

Thnx for the tips!

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

22 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

Related Questions

How to hide a part of a GUITexture that rotate ? 1 Answer

GUITexture is lagging my object 0 Answers

Multiple Cars not working 1 Answer

On Click GUI texture 0 Answers

Distribute terrain in zones 3 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