You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Plugins/Animancer/Examples/06 State Machines/06 Platformer/LocalPlayerBrain.cs

43 lines
1.7 KiB
C#

2 months ago
// Animancer // Copyright 2020 Kybernetik //
#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
using UnityEngine;
namespace Animancer.Examples.StateMachines.Platformer
{
/// <summary>
/// A brain for creatures controlled by local input (keyboard and mouse).
/// </summary>
[AddComponentMenu(Strings.MenuPrefix + "Examples/Platformer - Local Player Brain")]
[HelpURL(Strings.APIDocumentationURL + ".Examples.StateMachines.Platformer/LocalPlayerBrain")]
public sealed class LocalPlayerBrain : CreatureBrain
{
/************************************************************************************************************************/
[SerializeField] private CreatureState _Attack;
[SerializeField] private AdvancedJumpState _Jump;
/************************************************************************************************************************/
private void Update()
{
if (Input.GetButtonUp("Fire1"))// Left Click by default.
Creature.StateMachine.TrySetState(_Attack);
if (Input.GetButtonDown("Jump"))// Space by default.
Creature.StateMachine.TrySetState(_Jump);
if (Input.GetButtonUp("Jump"))
_Jump.IsHolding = false;
// GetAxisRaw rather than GetAxis because we don't want any smoothing.
MovementDirection = Input.GetAxisRaw("Horizontal");// A and D or Arrow Keys by default.
IsRunning = Input.GetButton("Fire3");// Left Shift by default.
}
/************************************************************************************************************************/
}
}