Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Character Move Manager
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace game_Input
- {
- public enum TransitionParameter
- {
- Moving,
- }
- public class characterMoveManager : MonoBehaviour
- {
- public float speed;
- public Animator animator;
- }
- }
- //Character State Base
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace game_Input
- {
- public class characterStateBase : StateMachineBehaviour
- {
- private characterMoveManager characterControl;
- public characterMoveManager GetCharacterControl(Animator animator)
- {
- if (characterControl == null)
- {
- characterControl = animator.GetComponentInParent<characterMoveManager>();
- }
- return characterControl;
- }
- }
- }
- //Idle State
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace game_Input
- {
- public class PlayerIdle : characterStateBase
- {
- // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
- override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
- {
- }
- // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
- override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
- {
- if (VirtualInputManager.Instance.moveRight || VirtualInputManager.Instance.moveLeft || VirtualInputManager.Instance.moveForward || VirtualInputManager.Instance.moveBackward)
- {
- animator.SetBool(TransitionParameter.Moving.ToString(), true);
- }
- }
- // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
- override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
- {
- }
- }
- }
- //Walk State
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace game_Input
- {
- public class PlayerWalk : characterStateBase
- {
- // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
- override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
- {
- }
- // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
- override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
- {
- if (VirtualInputManager.Instance.moveRight && VirtualInputManager.Instance.moveLeft)
- {
- animator.SetBool(TransitionParameter.Moving.ToString(), false);
- return;
- }
- if (VirtualInputManager.Instance.moveForward && VirtualInputManager.Instance.moveBackward)
- {
- animator.SetBool(TransitionParameter.Moving.ToString(), false);
- return;
- }
- if (!VirtualInputManager.Instance.moveRight && !VirtualInputManager.Instance.moveLeft && !VirtualInputManager.Instance.moveForward && !VirtualInputManager.Instance.moveBackward)
- {
- animator.SetBool(TransitionParameter.Moving.ToString(), false);
- return;
- }
- if (VirtualInputManager.Instance.moveForward)
- {
- GetCharacterControl(animator).transform.Translate(Vector3.forward * GetCharacterControl(animator).speed * Time.deltaTime);
- GetCharacterControl(animator).transform.rotation = Quaternion.Euler(0f, 0f, 0f);
- }
- if (VirtualInputManager.Instance.moveBackward)
- {
- GetCharacterControl(animator).transform.Translate(Vector3.forward * GetCharacterControl(animator).speed * Time.deltaTime);
- GetCharacterControl(animator).transform.rotation = Quaternion.Euler(0f, 180f, 0f);
- }
- if (VirtualInputManager.Instance.moveRight)
- {
- GetCharacterControl(animator).transform.Translate(Vector3.forward * GetCharacterControl(animator).speed * Time.deltaTime);
- GetCharacterControl(animator).transform.rotation = Quaternion.Euler(0f, 90f, 0f);
- }
- if (VirtualInputManager.Instance.moveLeft)
- {
- GetCharacterControl(animator).transform.Translate(Vector3.forward * GetCharacterControl(animator).speed * Time.deltaTime);
- GetCharacterControl(animator).transform.rotation = Quaternion.Euler(0f, -90f, 0f);
- }
- }
- // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
- override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement