// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2023 Kybernetik // #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value. using UnityEngine; using UnityEngine.Events; namespace Animancer.Examples.AnimatorControllers.GameKit { /// /// A which teleports back to the starting position, plays an animation then returns /// to the state. /// /// 3D Game Kit/Respawn /// https://kybernetik.com.au/animancer/api/Animancer.Examples.AnimatorControllers.GameKit/RespawnState /// [AddComponentMenu(Strings.ExamplesMenuPrefix + "Game Kit - Respawn State")] [HelpURL(Strings.DocsURLs.ExampleAPIDocumentation + nameof(AnimatorControllers) + "." + nameof(GameKit) + "/" + nameof(RespawnState))] public sealed class RespawnState : CharacterState { /************************************************************************************************************************/ [SerializeField] private ClipTransition _Animation; [SerializeField] private UnityEvent _OnEnterState;// See the Read Me. [SerializeField] private UnityEvent _OnExitState;// See the Read Me. private Vector3 _StartingPosition; /************************************************************************************************************************/ private void Awake() { _Animation.Events.OnEnd = Character.StateMachine.ForceSetDefaultState; _StartingPosition = transform.position; } /************************************************************************************************************************/ private void OnEnable() { Character.Animancer.Play(_Animation); Character.transform.position = _StartingPosition; _OnEnterState.Invoke(); } /************************************************************************************************************************/ private void OnDisable() { _OnExitState.Invoke(); } /************************************************************************************************************************/ public override bool CanExitState => false; /************************************************************************************************************************/ } }