久しぶりに使うと忘れてしまって凄くはまってしまうので、やり方のページを張ります。
普通に Get Compornent とか使ってもアクセスできません(独自なスクリプトは取り出せないぽい)ので、自前にアクセスするPlaymaker用のアクションを作成します。
作成したアクションは、Projectの中に入れるだけで認識してくてます。
https://hutonggames.fogbugz.com/default.asp?W623
一応コードも
Accessing External Scripts (Behaviors):
using UnityEngine;
public class MyBehavior : MonoBehaviour
{
public float testFloat;
}
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.ScriptControl)]
[Tooltip("Shows how to interface with a behavior on a game object")]
public class MyBehaviorAction : FsmStateAction
{
public MyBehavior myBehavior;
[UIHint(UIHint.Variable)]
public FsmFloat getTestFloat;
public override void OnUpdate()
{
getTestFloat.Value = myBehavior.testFloat;
}
}
}
Accessing a FSM from a custom script:
Code:
using UnityEngine;
using HutongGames.PlayMaker;
public class UseFSM : MonoBehaviour
{
public PlayMakerFSM behavior;
void Update ()
{
// getting named fsm variables
FsmFloat test = behavior.FsmVariables.GetFsmFloat("test");
// setting named fsm variables
test.Value = 0.5f;
// sending events
behavior.Fsm.Event("test");
}
}