Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Player Animation
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerAnimation : MonoBehaviour
- {
- private Animator animator;
- private CharacterController _controller;
- private bool _isGrounded;
- public void Start()
- {
- _controller = GetComponent<CharacterController>();
- animator = GetComponent<Animator>();
- }
- public void Update()
- {
- _isGrounded = _controller.isGrounded;
- bool isWalking = animator.GetBool("isWalking");
- bool isRunning = animator.GetBool("isRunning");
- bool leftPressed = Input.GetKey(KeyCode.A);
- bool rightPressed = Input.GetKey(KeyCode.D);
- bool runPressed = Input.GetKey(KeyCode.X);
- bool jumpPressed = Input.GetKeyDown(KeyCode.Space);
- OnStateEnter(); // TODO: check and make it better
- if ((leftPressed || rightPressed) && !isWalking)
- {
- animator.SetBool("isWalking", true);
- }
- if (!(leftPressed || rightPressed) && isWalking)
- {
- animator.SetBool("isWalking", false);
- }
- if (((leftPressed || rightPressed) && runPressed) && !isRunning)
- {
- animator.SetBool("isRunning", true);
- }
- if ((!(leftPressed || rightPressed) || !runPressed) && isRunning)
- {
- animator.SetBool("isRunning", false);
- }
- if (jumpPressed && _isGrounded)
- {
- animator.SetTrigger("Jumping");
- }
- }
- private void OnStateEnter()
- {
- animator.ResetTrigger("Jumping");
- }
- }
Add Comment
Please, Sign In to add comment