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 PISSDRANK8792 · Aug 01, 2013 at 03:24 AM · guionmousedown

Click on a gameObject to show/hide a GUI box help C#

i need help modifying two scripts

i have a lot of gameObjects, if you click in each one, it will show a text from a GUI in the mainCamera of a especific gameObject.

  • need* another text and a GUI box for each model you touch with the mouse button 1 on another or the same scripts

the followin script goes with each of one of the gameObjects

 using UnityEngine;
 using System.Collections;
 
 public class Character : MonoBehaviour
 {
     public string myWords = string.Empty;
         
     private void Start () 
     {    
     
     }
     
     private void Update ()
     {
         
     }
     
     public string GetWords ()    
     {
         return myWords;
     }    
 }


the follinw script is for the mainCamera it allows you to click on a model gameObject in the game and show the text attached for each obj, if you click on the mainCamara background no GUI is displayed! using UnityEngine; using System.Collections;

 public class UI_Demo : MonoBehaviour
 {
     private GameObject clicked = null;
     
     private void Start()
     {
     
     }
     
     private void Update ()
     {
         if (Input.GetMouseButtonDown(0)) 
         {
             RaycastHit hit;
             
             if (Physics.Raycast(Camera.mainCamera.ScreenPointToRay(Input.mousePosition), out hit))
             {                
                 if (hit.collider.gameObject.GetComponent<Character>() != null)
                     clicked = hit.collider.gameObject;
                 else
                     clicked = null;
             }
             else 
                 clicked = null;
         }
     }
     private void OnGUI()
     {
         if (clicked != null)
             GUI.Label(new Rect(15,15,200,25), clicked.GetComponent<Character>().GetWords());
         }
     }


i need help i'm in the process of learning C# and i'm stuck and in a hurry please help me how to figure it out and solve this ): sorry for the bad english ..

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 tw1st3d · Aug 01, 2013 at 05:42 AM

 using UnityEngine;
 using System.Collections;
 
 public class OpenMenuButton : MonoBehavior
 {
     /* Set this script on your actual game object */
     protected bool showMenu = false; 
     // Set showing the menu to false
     
     void OnMouseUp()
     {
         // When you click, change the variables value
         if(showMenu)
             showMenu = false;
         else
             showMenu = true; 
     }
     
     void OnGUI()
     {
         if(showMenu)
             // Your GUI Code
     }
 
 }
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

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Bringing window to back GUI.BringWindowToBack() 0 Answers

Setting Scroll View Width GUILayout 1 Answer

Card matching game 1 Answer

How do i cal second question in a window? 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