playMaker

Author Topic: Fsm Game Object does not contain a definetion for transform  (Read 192 times)

Empire

  • Playmaker Newbie
  • *
  • Posts: 10
Any one know how I can get this to work? I can't seem to reference the transform from a fsm game object:

Code: [Select]
{
[RequiredField]
[Tooltip("The Game Object to work with. NOTE: The Game Object must have a NavMeshAgent component attached.")]
[CheckForComponent(typeof(UnityEngine.AI.NavMeshAgent))]
public FsmOwnerDefault gameObject;
public FsmGameObject thing2Avoid;
public float EnemyDistanceRun = 4.0f;

private UnityEngine.AI.NavMeshAgent _agent;

// Code that requires the navimesh agent.
private void _getAgent()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}

_agent = go.GetComponent<UnityEngine.AI.NavMeshAgent>();
}

// Code that resets variables back to null.
public override void Reset()
{
gameObject = null;

}

// Code that runs on entering the state.
public override void OnEnter()
{
// Get the Navimesh agent
_getAgent();

// Invoke Method here
RunAway();

Finish();
}

void RunAway()
{
float distance = Vector3.Distance(Fsm.GameObject.transform.position, thing2Avoid.transform.position);

if (distance < EnemyDistanceRun)
{
Vector3 dirToPlayer = Fsm.GameObject.transform.position - thing2Avoid.transform.position;
Vector3 newPos = (Fsm.GameObject.transform.position + dirToPlayer) * 2;
_agent.SetDestination(newPos);
}
}

}

Empire

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Fsm Game Object does not contain a definetion for transform
« Reply #1 on: May 24, 2021, 05:40:55 PM »
Nevermind, just had to convert the fsm game object to a Unity Game Object:

Code: [Select]
public FsmGameObject thing2Avoidfsm;
private GameObject thing2Avoid;

thing2Avoid = thing2Avoidfsm.Value;