Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Player : MonoBehaviour {
- private float inputDir; // gia tri x cua moveVector
- private float verticalvelocity; // gia tri y cua moveVector
- public float gravity = 0; // gia tri gravity
- public float tocDo;
- private Vector2 moveVector;
- private CharacterController controller;
- // Use this for initialization
- void Start () {
- controller = GetComponent<CharacterController> ();
- }
- // Update is called once per frame
- void Update () {
- // Di chuyen theo chieu ngang trong Axis
- inputDir = Input.GetAxis ("Chieu Ngang") * tocDo;
- moveVector = new Vector2 (inputDir,verticalvelocity);
- controller.Move (moveVector * Time.deltaTime);
- if (controller.isGrounded) {
- verticalvelocity = 0; // neu player o duoi dat thi bang 0
- // jump
- if (Input.GetKeyDown (KeyCode.Space))
- {
- verticalvelocity = 10;
- }
- }
- else
- {
- verticalvelocity -= gravity; // van toc Y bang vtocY tru gravity
- }
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement