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 Donovan_Rucastle · Oct 30, 2011 at 12:11 PM · guitooltip

tooltip on GUI layout ?

Hi All I am using GUILayout. But my problem is that I want to implament a tooltip into every button created how would I do that ?

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 //============================================================================
 // TowerManager
 //----------------------------------------------------------------------------
 // 
 //============================================================================
 public class TowerManager : MonoBehaviour
 {
     //----------------------------------
     // Public
     //----------------------------------
     public List<Tower> towers;
 
     //----------------------------------
     // Private
     //----------------------------------
     private int? activeButton = null;
     private GUILayoutOption[] button = {GUILayout.Height(30), GUILayout.Width(30) };
 
     //----------------------------------
     // SelectedTower
     //----------------------------------
     public Tower selected
     {
         get
         {
             if( activeButton.HasValue )
             {
                 return towers[(int)activeButton];
             }
 
             return null;
         }
     }
 
     //----------------------------------
     // Ghost
     //----------------------------------
     public Tower ghost;
 
     //----------------------------------
     // AWAKE
     //----------------------------------
     void Awake()
     {
     }
 
     //----------------------------------
     // ONGUI
     //----------------------------------
     void OnGUI()
     {
         GUILayout.BeginArea( new Rect( Screen.width - 50, 25, 50, Screen.height ) );
         GUILayout.BeginVertical();
 
         foreach( Tower tower in towers )
         {
             if( activeButton != towers.IndexOf(tower) &&
                 GUILayout.Button(tower.icon, button ) )
             {
                 Griddy.Terrain.Clear();
                 activeButton = towers.IndexOf(tower);
                 Griddy.Cursor.state = CursorState.PlaceBuilding;
                 SetGhost( selected );
             }
             else if( activeButton == towers.IndexOf(tower) )
             {
                 float a = Mathf.PingPong( Time.time, 1 );
                 GUI.color = new Color( 1, 1, 1, a );
                 GUILayout.Label(tower.icon, button );
                 GUI.color = Color.white;
             }
         }
 
         GUILayout.FlexibleSpace();
         GUILayout.EndVertical();
         GUILayout.EndArea();
     }
 
     // UPDATE
     void Update()
     {
         if( Input.GetKeyDown( KeyCode.Space ) )
         {
             Clear();
             Griddy.Cursor.Clear();
         }
         if( ghost != null)
         {
             if( Griddy.Grid.activeMarker != null)
             {
                 ghost.SetPosition( Griddy.Grid.activeMarker.position.x, Griddy.Grid.activeMarker.position.y );
             }
             else
             {
                 ghost.SetPosition( -100, -100 );
             }
         }
     }
     
     void SetGhost( Tower _ghost )
     {
         if( ghost != null )
             Destroy(ghost.gameObject);
     
         ghost = (Instantiate( _ghost.gameObject ) as GameObject).GetComponent<Tower>();
     
         foreach( Material material in ghost.renderer.materials )
         {
             material.shader = Shader.Find("Transparent/Diffuse");
             material.color = new Color( material.color.r, material.color.g, material.color.b, 0.7f );
         }
     }
     
     public void Clear()
     {
         activeButton = null;
         Destroy( ghost );
     }
 }    

Could someone please format my code because my internet is down and I am using my blackberry and cannot do it myself ? :(

Comment
Add comment · Show 6
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 syclamoth · Oct 30, 2011 at 12:34 PM 0
Share

There you go! Damn that was painful. But easier on the eyes, now.

Why don't you use the inbuilt tooltip functionality? It's right there in the GUIContent!

avatar image Donovan_Rucastle · Oct 30, 2011 at 12:42 PM 0
Share

Oh ha ha but how would I do that beacuse when I try it gives me errors ?

avatar image syclamoth · Oct 30, 2011 at 12:47 PM 0
Share

What kind of errors? All that means is that you're not making the GUIContent properly. I'm expecting something like this-

 GUI.Label(some rect, new GUIContent("name on the label", "tooltip on the label"));

Then, you can get that using GUI.tooltip whenever you mouse over something!

avatar image DaveA · Oct 30, 2011 at 05:42 PM 0
Share

That's an answer. PLEASE use answer, or I'll start posting answers just to have an answer. I'd rather you get the credit.

avatar image Donovan_Rucastle · Nov 01, 2011 at 04:02 PM 0
Share

Yes please post an answer because I don't know how to make it answered if no one has actually posted one ?

Show more comments

1 Reply

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

Answer by Donovan_Rucastle · Nov 01, 2011 at 09:19 PM

@syclamoth thank that did it I was referring to it in the other script :/ don't know what I was thinking.

Answer from @ syclamoth

What kind of errors? All that means is that you're not making the GUIContent properly. I'm expecting something like this-

GUI.Label(some rect, new GUIContent("name on the label", "tooltip on the label")); Then, you can get that using GUI.tooltip whenever you mouse over something!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I create complex tooltips 2 Answers

tooltip to show from array C# 1 Answer

Why can't I get my tooltip to show only when there is a tooltip set? 2 Answers

Display tooltips for objects in scene 1 Answer

automatic gui tooltips 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