Add behavior logic to your character
Getting a reference to the actor
using UnityEngine;
using Lightbug.CharacterControllerPro.Core; //<-- Required
public class CharacterLogic: Monobehaviour
{
[SerializeField]
CharacterActor characterActor = null;
}
Update message
Because the actor is a rigid body that's going to be affected by the physics simulation, all the logic must be located on FixedUpdate.
using UnityEngine;
using Lightbug.CharacterControllerPro.Core; //<-- Required
public class CharacterLogic: Monobehaviour
{
[SerializeField]
CharacterActor characterActor = null;
void FixedUpdate()
{
// Put the logic here ...
}
}
Execution order
Because the actor runs its own update, it is important for the behavior logic (user-defined) to run before it. In Unity the execution order of scripts can be specified either in the project settings, or as a c# attribute called DefaultExecutionOrder.
By default, the CharacterActor class uses an execution order of 10. This means all scripts without the attribute (execution order = 0) will run before CharacterActor, which is what we want.
//CharacterActorOrder = 10
[DefaultExecutionOrder(ExecutionOrder.CharacterActorOrder)]
public class CharacterActor : MonoBehaviour
{
...
}
Last updated