Guest User

Untitled

a guest
Jan 24th, 2017
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CharacterController : MonoBehaviour {
  5.  
  6.     public Rigidbody Character;
  7.     private float MaxSpeed = 5.0f;
  8.  
  9.     // Use this for initialization
  10.     void Start () {
  11.    
  12.     }
  13.    
  14.     // Update is called once per frame
  15.     void Update () {
  16.         if (Input.GetKey (KeyCode.D)) {
  17.             float force = -1000 * Time.deltaTime;
  18.             Character.AddForce(force,0,0);
  19.         }
  20.  
  21.         if (Input.GetKey (KeyCode.A)) {
  22.             float force = 1000 * Time.deltaTime;
  23.             Character.AddForce(force,0,0);
  24.         }
  25.  
  26.         if (Input.GetKeyDown (KeyCode.Space)) {
  27.             Jump ();
  28.         }
  29.  
  30.         if (Character.velocity.x > 1) {
  31.             if (Character.velocity.x > MaxSpeed) { 
  32.                 Character.velocity = new Vector3 (MaxSpeed, Character.velocity.y, 0);
  33.             }
  34.         } else if (Character.velocity.x < 1) {
  35.             if (Character.velocity.x < -MaxSpeed) {
  36.                 Character.velocity = new Vector3 (-MaxSpeed, Character.velocity.y, 0);
  37.             }          
  38.         }
  39.     }
  40.  
  41.     void Jump()
  42.     {
  43.         Character.velocity = new Vector3 (Character.velocity.x, 5, 0);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment