Search Unity

Button like behaviour.

Discussion in 'Scripting' started by jmcguire, Aug 31, 2005.

  1. jmcguire

    jmcguire

    Joined:
    Aug 31, 2005
    Posts:
    2
    Is there a built-in button like behavior or does anyone have an example of how you could setup a target object to respond when it is clicked on?
     
  2. nmceri

    nmceri

    Joined:
    Aug 4, 2005
    Posts:
    56
    Check in users/shared/unity/script tutorial/assets/
    In there you'll find some examples that will help you out.
    I think that's where they are by default anyway.
     
  3. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,558
    Code (csharp):
    1.  
    2. function OnMouseDown () {
    3.     /* load the level named start */
    4.     Application.LoadLevel ("start");
    5. }
    6.  
    Also, if this is a GUIText button, you can make it expand and change colour by putting this script into it ...

    Code (csharp):
    1.  
    2. /* This behavior script changes the material color to the
    3. highlightColor when the mouse hovers over the text.
    4. The highlightColor can be modified in the inspector. */
    5.  
    6. /* It also scales the object to be slightly larger on mouse enter,
    7. then back to normal size when the mouse leaves the object. */
    8.  
    9. var highlightColor = Color.yellow;
    10.    
    11. function OnMouseEnter () {
    12.     guiText.material.color = highlightColor;
    13.     transform.localScale = Vector3 (2.2, 2.2, 2.2);
    14. }
    15.  
    16. function OnMouseExit () {
    17.     guiText.material.color = Color.white;
    18.     transform.localScale = Vector3 (2, 2, 2);
    19. }
    20.  
    Welcome to Unity! I also agree with nmceri, check out all of the scripting examples ... alot of basic functionality is shown in them.
     
  4. jmcguire

    jmcguire

    Joined:
    Aug 31, 2005
    Posts:
    2
    Thank you both for the info. I'll spend some more time with the provided samples and documentation. I guess I just need to locate the scripting reference and start reading up on what event different object respond to.