Alright boys, girls and small green things from alpha centuri...
I have just made my first custom action, to get the velocity of the character controller and store it in a Vector3. I'm posting it here for 2 reasons. First, because others may find it useful. 2, so that it can be checked and improved.
Licence... just use the damn thing, I copied most of the code from the other actions anyway.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Character)]
[Tooltip("Gets the velocity of the attached character controller")]
public class GetControllerVelocity : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(CharacterController))]
public FsmOwnerDefault gameObject;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmVector3 storeResult;
public bool everyFrame;
GameObject previousGo;
CharacterController controller;
public override void Reset()
{
gameObject = null;
storeResult = null;
everyFrame = false;
}
public override void OnEnter()
{
doGetVelocity();
if (!everyFrame) Finish();
}
public override void OnUpdate()
{
doGetVelocity();
}
public void doGetVelocity()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;
if (go != previousGo)
{
controller = go.GetComponent<CharacterController>();
previousGo = go;
}
if (controller != null)
{
storeResult.Value = controller.velocity;
}
}
}
}
I know that the documents say don't use the same namespace, but I couldn't get it to recognise FsmStateAction any other way. If someone knows how to fix that, please tell me. I'm still fairly new to namespaces.