Guest User

SpeedUpOnKeyPressed

a guest
Jun 21st, 2014
706
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SpeedUpOnKeyPressed : MonoBehaviour {
  5.    
  6.     private PlayerMove playerMove;
  7.    
  8.     float OriginalSpeed;
  9.     float OriginalAccel;
  10.     float OriginalAirAccel;
  11.     public float newMaxSpeed =15f;
  12.     public float newMaxAccel=95f;
  13.     public float newAirAccel=25f;
  14.     // Use this for initialization
  15.     void Start () {
  16.         playerMove = GetComponent<PlayerMove>();
  17.         OriginalSpeed=playerMove.maxSpeed;
  18.         OriginalAccel=playerMove.accel;
  19.         OriginalAirAccel=playerMove.airAccel;
  20.     }
  21.    
  22.     // Update is called once per frame
  23.     void Update () {
  24.         if (Input.GetKeyDown(KeyCode.B)) {
  25.             if(playerMove.maxSpeed!=newMaxSpeed) {
  26.                 playerMove.maxSpeed=newMaxSpeed;
  27.             }
  28.             if(playerMove.accel!=newMaxAccel) {
  29.                 playerMove.accel=newMaxAccel;
  30.             }
  31.             if(playerMove.airAccel!=newAirAccel) {
  32.                 playerMove.airAccel=newAirAccel;
  33.             }
  34.             playerMove.animator.SetBool ("SpeedUp", true);
  35.         }
  36.         if (Input.GetKeyUp(KeyCode.B)) {
  37.             if(playerMove.maxSpeed!=OriginalSpeed) {
  38.                 playerMove.maxSpeed=OriginalSpeed;
  39.             }
  40.             if(playerMove.accel!=OriginalAccel) {
  41.                 playerMove.accel=OriginalAccel;
  42.             }
  43.             if(playerMove.airAccel!=OriginalAirAccel) {
  44.                 playerMove.airAccel=OriginalAirAccel;
  45.             }
  46.             playerMove.animator.SetBool ("SpeedUp", false);
  47.         }
  48.     }
  49. }
RAW Paste Data