Advertisement
LordSolrac2

PlayerCtrl.cs

Oct 6th, 2015
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlyCtrl : MonoBehaviour {
  5.     public float Speed = 8;
  6.     public float Accel = 12;
  7.     public float Gravity = 20;
  8.     public float JumpHeight = 12;
  9.     private float GroundDistance;
  10.     private float CurrentSpeed;
  11.     private float TargetSpeed;
  12.     private Vector3 Target;
  13.     private Transform Targt;
  14.     private float StepSpeed;
  15.     private Vector3 moveDirection = Vector3.zero;
  16.     private bool isMoving = false;
  17.     // Use this for initialization
  18.     void Start () {
  19.    
  20.     }
  21.    
  22.     // Update is called once per frame
  23.     void Update () {
  24.         CharacterController controller = GetComponent<CharacterController>();
  25.         TargetSpeed = Input.GetAxis("Horizontal") * Speed;
  26.         if(TargetSpeed != 0){
  27.             if(Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)){
  28.                 moveDirection.x=Speed/4;
  29.                 controller.Move (moveDirection * Time.deltaTime * Speed);
  30.             }
  31.             if(Input.GetKey(KeyCode.LeftArrow ) || Input.GetKey(KeyCode.A)){ moveDirection.x=-Speed/4; isMoving=true; }//transform.rotation.y=-180;}
  32.             if (isMoving == true) {
  33.                 controller.Move (moveDirection * Time.deltaTime * Speed);
  34.             }
  35.         }
  36.  
  37.         if (controller.isGrounded) {
  38.             if (Input.GetButton ("Jump")) {
  39.                 moveDirection.y = JumpHeight;
  40.                 controller.Move (moveDirection * Time.deltaTime * (Speed*12));
  41.             }
  42.         } else { //Fall
  43.             moveDirection.y = -Gravity/2;
  44.             controller.Move (moveDirection * Time.deltaTime * (Speed/2));
  45.         }
  46.     }
  47.        
  48.     ////////////END OF CLASS////////////
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement