mt new additions

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

I will give the answer a shot :slight_smile:

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?

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

Actually, I get an error when the script is placed directly on a GUIText for the reason that you pointed out.

you know, i haven’t gotten around to actually trying it out. I just assumed it had been tested and worked. :sweat_smile:

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

Since the JavaScript is being compiled into .Net bytecode (or something like that) you could try using the .Net Object GetType() method

classType = guiElement.GetType();

You might need to use the Name property on the returned type

classType = guiElement.GetType().Name;

I will probably play a little with this this evening. Maybe I might update the wiki :shock:

Awesome, that worked! :smile:

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

guiElement.GetType().Name returns “GUIText” or “GUITexture”.

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:

   // C#
   if( object.GetType() == typeof(GUITexture) ) {
   ...
   }

This is not required in Javascript, as type names are automatically also the type object:

   // UnityScript
   if( object.GetType() == GUITexture ) {
   ...
   }