Advertisement
rodrigofbm

Player

Aug 8th, 2015
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Player : MonoBehaviour {
  5.     public float speed = 1.5F;
  6.     public float jumpSpeed = 8.0F;
  7.     public float gravity = 20.0F;
  8.     private Vector3 moveDirection = Vector3.zero;
  9.  
  10.  
  11.  
  12.     void Start(){
  13.        
  14.         }
  15.  
  16.  
  17.     void Update() {
  18.         CharacterController controller = GetComponent<CharacterController>();
  19.         if (controller.isGrounded) {
  20.             moveDirection = new Vector3(0, 0, speed);
  21.             moveDirection = transform.TransformDirection(moveDirection);
  22.             moveDirection *= speed;
  23.             if (Input.GetButtonDown("Jump"))
  24.                 moveDirection.y = jumpSpeed;
  25.            
  26.         }
  27.         moveDirection.y -= gravity * Time.deltaTime;
  28.         controller.Move(moveDirection * Time.deltaTime);
  29.  
  30.        
  31.    
  32.  
  33.  
  34.  
  35.  
  36.     }
  37.  
  38.    
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement