Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. public class MoveClips : MonoBehaviour
  2. {
  3.     public float speed = 10f;
  4.  
  5.     Rigidbody rb;
  6.     bool isGrounded;
  7.     Animation P_GG;
  8.     // Start is called before the first frame update
  9.     void Start()
  10.     {
  11.         rb = GetComponent<Rigidbody>();
  12.         P_GG = GetComponent<Animation>();
  13.     }
  14.  
  15.     // Update is called once per frame
  16.     void FixedUpdate()
  17.     {
  18.         MovementLogic();
  19.     }
  20.  
  21.     private void MovementLogic()
  22.     {
  23.         float moveHorizontal = Input.GetAxis("Horizontal");
  24.         if (Input.GetKey(KeyCode.A))
  25.         {
  26.             P_GG.Play("GL");
  27.         }
  28.         if (Input.GetKey(KeyCode.D))
  29.         {
  30.             P_GG.Play("GR");
  31.         }
  32.  
  33.         float moveVertical = Input.GetAxis("Vertical");
  34.  
  35.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
  36.  
  37.         rb.AddForce(movement * speed);
  38.     }
  39.  
  40.     void OnCollisionEnter(Collision collision)
  41.     {
  42.         IsGroundedUpate(collision, true);
  43.     }
  44.  
  45.     void OnCollisionExit(Collision collision)
  46.     {
  47.         IsGroundedUpate(collision, false);
  48.     }
  49.  
  50.     private void IsGroundedUpate(Collision collision, bool value)
  51.     {
  52.         if (collision.gameObject.tag == ("Ground"))
  53.         {
  54.             isGrounded = value;
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement