Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

RollOver issue within a hierarchy

Discussion in 'Scripting' started by ddurieux, Jun 27, 2007.

  1. ddurieux

    ddurieux

    Joined:
    Mar 1, 2007
    Posts:
    33
    Hi, I am ttrying to create a RollOver script to go with my Interface that I can apply to the top most hiearchy (ie menu>elements) then call the elements I want [ie so I dont have to place button scripts on every element just to have rollovers.

    I am pretty new to the scripting part but I managed to create a rollover that works somewhat. However, I am trying to call some gameObjects in the scene and then enable disable them depending on the rollover. Hoever I keep getting erros that UNITY cannot find my the variables "enabled". Here is the code I have:

    Code (csharp):
    1.  var normalTexture;
    2.  var hoverTexture : GUITexture;
    3.  var pressedTexture : GUITexture;
    4.  var messagee : GameObject;
    5.  var message = "ButtonPressed";
    6.  
    7. var menuBkg;
    8.  
    9.  
    10.  
    11.  private var state = 0;
    12.  private var myGUITexture : GUITexture;
    13.  
    14.  
    15.  //menuBkg = GameObject.find("menuBkg");
    16.  
    17.  //myGUITexture = GameObject.find("APUprogr0");
    18.  
    19. function Start() {
    20.     menuBkg = GameObject.Find("menuBkg");
    21.     normalTexture = GameObject.Find("menuBkg/APUcmplte1");
    22. }
    23.  
    24.  
    25.  
    26.  
    27. var highlightColor = Color.yellow;
    28.    
    29. function OnMouseEnter () {
    30.     hoverTexture.color.a = 0;
    31.     normalTexture.enabled = false;
    32.     Debug.Log("hi"+ menuBkg);
    33. }
    34.  
    35. function OnMouseExit () {
    36.     hoverTexture.color.a = 100;
    37. }
    The problem arises when the normalTexture element is called...take it out its ok. This script is place at the topmost chain and looks for elements within that hierarchy.

    I appreciate any help and tahnks in advance.
     
  2. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    You haven't declared normalTexture to be of type GUITexture, like you have for the others.

    Since GameObject.Find by default returns the GameObject itself, and not the GuiTexture component, the normalTexture points to a GameObject, which does not have an "enabled" member.