// Animancer // Copyright 2020 Kybernetik // #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value. using Animancer.Examples.StateMachines.Brains; using Animancer.FSM; using UnityEngine; namespace Animancer.Examples.StateMachines.Weapons { /// /// Causes a to attack in response to player input. /// /// Normally this would be part of the , but since we want to demonstrate both /// and in this example we have implemented it separately. /// [AddComponentMenu(Strings.MenuPrefix + "Examples/Weapons - Attack Input")] [HelpURL(Strings.APIDocumentationURL + ".Examples.StateMachines.Weapons/AttackInput")] public sealed class AttackInput : MonoBehaviour { /************************************************************************************************************************/ [SerializeField] private CreatureState _Attack; [SerializeField] private float _AttackInputTimeOut = 0.5f; private StateMachine.InputBuffer _InputBuffer; /************************************************************************************************************************/ private void Awake() { _InputBuffer = new StateMachine.InputBuffer(_Attack.Creature.StateMachine); } /************************************************************************************************************************/ private void Update() { if (Input.GetButtonDown("Fire2"))// Right Click by default. { _InputBuffer.TrySetState(_Attack, _AttackInputTimeOut); } else { _InputBuffer.Update(); } } /************************************************************************************************************************/ } }