Advertisement
Guest User

Untitled

a guest
Nov 20th, 2016
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Player : MonoBehaviour {
  5.  
  6. private float inputDir; // gia tri x cua moveVector
  7. private float verticalvelocity; // gia tri y cua moveVector
  8.  
  9. public float gravity = 0; // gia tri gravity
  10. public float tocDo;
  11.  
  12. private Vector2 moveVector;
  13. private CharacterController controller;
  14.  
  15.  
  16.  
  17. // Use this for initialization
  18. void Start () {
  19. controller = GetComponent<CharacterController> ();
  20. }
  21.  
  22. // Update is called once per frame
  23. void Update () {
  24. // Di chuyen theo chieu ngang trong Axis
  25. inputDir = Input.GetAxis ("Chieu Ngang") * tocDo;
  26. moveVector = new Vector2 (inputDir,verticalvelocity);
  27. controller.Move (moveVector * Time.deltaTime);
  28.  
  29. if (controller.isGrounded) {
  30. verticalvelocity = 0; // neu player o duoi dat thi bang 0
  31.  
  32. // jump
  33. if (Input.GetKeyDown (KeyCode.Space))
  34. {
  35. verticalvelocity = 10;
  36. }
  37.  
  38. }
  39. else
  40. {
  41. verticalvelocity -= gravity; // van toc Y bang vtocY tru gravity
  42. }
  43.  
  44.  
  45. }
  46. }
Advertisement
RAW Paste Data Copied
Advertisement