dronkowitz

CharacterAnimationController.cs

Apr 7th, 2021 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CharacterAnimationController : MonoBehaviour
  6. {
  7.     public Animator anim;
  8.     private bool wasGrounded = true;
  9.     private Rigidbody body;
  10.     private bool rolling;
  11.     private LayerMask groundMask;
  12.     // Start is called before the first frame update
  13.     void Awake()
  14.     {
  15.         body = transform.parent.GetComponent<Rigidbody>();
  16.         groundMask = 8;
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.         bool grounded = Physics.CheckSphere(body.transform.position + (-body.transform.up * 0.55f), 0.48f, groundMask);
  23.         anim.SetFloat("Speed", body.velocity.magnitude);
  24.  
  25.         if (wasGrounded && !grounded)
  26.         {
  27.             wasGrounded = false;
  28.             anim.SetTrigger("Launch");
  29.             anim.SetBool("Inair", true);
  30.            
  31.         }
  32.  
  33.         if(!wasGrounded && grounded)
  34.         {
  35.             wasGrounded = true;
  36.            
  37.             anim.SetBool("Inair", false);
  38.         }
  39.  
  40.         if (Input.GetKeyDown(KeyCode.Q))
  41.         {
  42.             rolling = !rolling;
  43.             if (rolling) anim.SetTrigger("RollStart");
  44.             else anim.SetTrigger("RollEnd");
  45.         }
  46.  
  47.        
  48.     }
  49. }
Add Comment
Please, Sign In to add comment