playMaker

Author Topic: set property on a variable gameobject  (Read 3991 times)

Maart

  • Junior Playmaker
  • **
  • Posts: 88
set property on a variable gameobject
« on: December 20, 2012, 05:37:30 AM »
what is the best way to set a property of a component of a variable gameobject?

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: set property on a variable gameobject
« Reply #1 on: December 20, 2012, 11:22:35 AM »
well let's say you know you want to set the render depth of the camera component to something.

You first create a new gameObject and object variable. You redefine the object variable to UnityEngine/camera .
Then you use getComponent on your gameObject variable, and save the result as the object variable. Since you defined the object variable as the type "camera" it will automatically only get components of that type. Then you can use a set property action on your object variable to edit the properties of the component it contains (in this case the camera component).
This is by far the most versatile use of the set property action. Of course just for the sake of staticity and cleanliness most of the time you will just want to drag in the component and set it directly.

best,
kiriri
Best,
Sven