Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Player : MonoBehaviour {
  5.  
  6. private Animator anim;
  7. private CharacterController controller;
  8.  
  9. public float speed = 6.0f;
  10. public float turnSpeed = 60.0f;
  11. private Vector3 moveDirection = Vector3.zero;
  12. public float gravity = 20.0f;
  13.  
  14. void Start () {
  15. controller = GetComponent <CharacterController>();
  16. anim = gameObject.GetComponentInChildren<Animator>();
  17. }
  18.  
  19. void Update (){
  20. if (Input.GetKey ("up")) {
  21. anim.SetInteger ("AnimationPar", 1);
  22. } else {
  23. anim.SetInteger ("AnimationPar", 0);
  24. }
  25.  
  26. if(controller.isGrounded){
  27. moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
  28. }
  29.  
  30. float turn = Input.GetAxis("Horizontal");
  31. transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
  32. controller.Move(moveDirection * Time.deltaTime);
  33. moveDirection.y -= gravity * Time.deltaTime;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement