Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlyCtrl : MonoBehaviour {
- public float Speed = 8;
- public float Accel = 12;
- public float Gravity = 20;
- public float JumpHeight = 12;
- private float GroundDistance;
- private float CurrentSpeed;
- private float TargetSpeed;
- private Vector3 Target;
- private Transform Targt;
- private float StepSpeed;
- private Vector3 moveDirection = Vector3.zero;
- private bool isMoving = false;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- CharacterController controller = GetComponent<CharacterController>();
- TargetSpeed = Input.GetAxis("Horizontal") * Speed;
- if(TargetSpeed != 0){
- if(Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)){
- moveDirection.x=Speed/4;
- controller.Move (moveDirection * Time.deltaTime * Speed);
- }
- if(Input.GetKey(KeyCode.LeftArrow ) || Input.GetKey(KeyCode.A)){ moveDirection.x=-Speed/4; isMoving=true; }//transform.rotation.y=-180;}
- if (isMoving == true) {
- controller.Move (moveDirection * Time.deltaTime * Speed);
- }
- }
- if (controller.isGrounded) {
- if (Input.GetButton ("Jump")) {
- moveDirection.y = JumpHeight;
- controller.Move (moveDirection * Time.deltaTime * (Speed*12));
- }
- } else { //Fall
- moveDirection.y = -Gravity/2;
- controller.Move (moveDirection * Time.deltaTime * (Speed/2));
- }
- }
- ////////////END OF CLASS////////////
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement