Redirecting you to bearmacstudios.com.... BearMac Studios: Quick help with understanding UnityScript

Pages

Friday, January 27, 2012

Quick help with understanding UnityScript

In a UnityScript script you will see something like this :
gameObject.GetComponents("MyScript").BooleanVariable = true;

Now for the people who look at that like "wtf?"
Here's a simple way to understand that;
Say I need Unity to find my computer and turn the power buttton to on, in a Java or UnityScript environment I would tell unity
MyHouse.MyRoom.Desk.Computer.PowerButton = on;

So to access a script named PowerButton on a gameobject named computer and change the Boolean variable powerButton to an on state we'd approach it like this;
GameObject.Find("computer").GetComponent("PowerButton").powerButton = true;

I saw this explanation awhile ago and it really helped me teach myself how make things happen in Unity.

No comments:

Post a Comment