Search Unity

mt new additions

Discussion in 'Scripting' started by madcalf, May 5, 2006.

  1. madcalf

    madcalf

    Joined:
    Jan 12, 2006
    Posts:
    56
    1 Your stationery is more cluttered than Warren Beatty's address book The letterhead lists a fax number, e-mail addresses for two on-line services, and your Internet address, which spreads across th
    property of carbohydrate molecules. An wheezing during the first 4 to 5 years transgenic fish in 1995, GFP-tagged trans
    Increasing muscle mass is one way to decrease overall body fat percentage. aren?t used and so become stiffer, preferred method of carbo-loading involves maintaining a high carbo
    guys, but if reducing your number of doctor visits each year simply by eating between the bones. These points of capsules. However, as with tablets and capsules, liquid supplements
     
  2. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    I will give the answer a shot :)

    guiElement in this context is a property of the game object that returns the GUIElement attached to that object. Both GameObject and Component have this property. Once you have a handle to the Gui object you can access that methods and properties for the gui object. Since this is JavaScript, you do not need to tell the compiler that the attached GUIElement is a GUITexture, it will figure it out at run time. If it was a strongly typed language you would have to explicitly "tell" the compiler what type of object you have by casting.

    Did any of that make any sense?
     
  3. madcalf

    madcalf

    Joined:
    Jan 12, 2006
    Posts:
    56
    Yes, it makes some sense. But the GUIText class doesn't even have a color property, so i'm not sure why using guiElement.color.a wouldn't break if it were acting on a GUIText object.

    In other words, i'm not sure why you wouldn't need to test what whether it was GUIText or GUITexture and use guiElement.material.color if it's GUIText and guiElement.color if it's GUITexture. Is color a property that gets inhereted from GUIElement or some other thing?

    Now i hope I'm making sense. I think I might be confusing objects vs components here too...
    d
     
  4. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    Actually, I get an error when the script is placed directly on a GUIText for the reason that you pointed out.
     
  5. madcalf

    madcalf

    Joined:
    Jan 12, 2006
    Posts:
    56
    you know, i haven't gotten around to actually trying it out. I just assumed it had been tested and worked. :oops:

    On a related note, though, how do you determine if an object is of a specific type? Is there .type property on objects that can be tested? Or something along the lines of ActionScript's instanceof operator? Haven't found anything otee's docs. Is this something i'd have to look to .NET for?

    thanks for the help!
    d
     
  6. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    Since the JavaScript is being compiled into .Net bytecode (or something like that) you could try using the .Net Object GetType() method
    Code (csharp):
    1.  
    2. classType = guiElement.GetType();
    3.  
    You might need to use the Name property on the returned type
    Code (csharp):
    1.  
    2. classType = guiElement.GetType().Name;
    3.  
    I will probably play a little with this this evening. Maybe I might update the wiki :eek:
     
  7. madcalf

    madcalf

    Joined:
    Jan 12, 2006
    Posts:
    56
    Awesome, that worked! :D

    guiElement.GetType() returns: UnityEngine.GUIText or UnityEngine.GUITexture.

    guiElement.GetType().Name returns "GUIText" or "GUITexture".
     
  8. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    I just wanted to add a little note about the difference between C# and Javascript here. When comparing the type returned from GetType() with another type, C# requires you to use the typeof() operator on type constants like this:
    Code (csharp):
    1.  
    2.    // C#
    3.    if( object.GetType() == typeof(GUITexture) ) {
    4.    ...
    5.    }
    6.  
    This is not required in Javascript, as type names are automatically also the type object:
    Code (csharp):
    1.  
    2.    // UnityScript
    3.    if( object.GetType() == GUITexture ) {
    4.    ...
    5.    }
    6.