0
\$\begingroup\$

I am trying to create my own action in Behavior Designer. However i cannot seem to get the game object that designer is attached to. if i attempt to do:

protected Combatant enemyCombatantObject;

public override void OnAwake()
{
    enemyCombatantObject = GameObject.GetComponent<Combatant>();
    base.OnAwake();
}

It gives me an error:

the property or indexer 'Task.GameObject' cannot be used in this context because it lacks the get accessor

Can anyone tell me how to get the GameObject that the script is attached to?

\$\endgroup\$
1
  • \$\begingroup\$ There is no such thing as a "Behavior Designer" in Unity. I think you are just talking about writing script code. Or is that some plugin you've downloaded? \$\endgroup\$
    – Philipp
    Commented May 21, 2017 at 12:19

1 Answer 1

1
\$\begingroup\$

Use gameObject.GetComponent<Combatant>();. Note the small g. gameObject is the object the script is attached to.

GameObject is the class of all game objects. You can use GameObject to call methods which aren't specific to any particular game object ("static methods"), like GameObject.CreatePrimitive or GameObject.Find. You also need to use GameObject when you want to declare a variable which holds a reference to a game object.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .