playMaker

Author Topic: Can't Access Properties Of A Global GameObject  (Read 5801 times)

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Re: Can't Access Properties Of A Global GameObject
« Reply #15 on: April 09, 2014, 12:58:23 PM »
If I do a find gameObject at runtime...how exactly do I access it's scripts variables?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Can't Access Properties Of A Global GameObject
« Reply #16 on: April 09, 2014, 01:11:22 PM »
If I do a find gameObject at runtime...how exactly do I access it's scripts variables?

Since there can be any number of components/monobehaviors on a GameObject you must identify the specific one you want to address. Get Component is used to identify which script you want, its stored in an Object variable and you have to predefine in that Object variable which script it is to look for when Get Component searches the target GameObject.

If you can work strictly in the scene its easier to affect script variables without Get Component (drag the script into the action stack and release), but assuming that both sides will be spawned from a prefab means you have to get everything at runtime and its a little more complex. The linked video tutorial covers both of those scenarios.

After you use Get Component to store the script in an Object variable then you can directly Get/Set variables with Get Property and Set Property actions. If the target GameObject is destroyed, then obviously you need to re-target and fill the Object variable(s) again because the connection has been lost.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D