Advertisement
Guest User

script

a guest
Mar 14th, 2013
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.46 KB | None | 0 0
  1.     using UnityEngine;
  2.     using System.Collections;
  3.      
  4.     public class script : MonoBehaviour {
  5.      
  6.             public float currentSpeed;
  7.             public float walkSpeed            = 6F;
  8.             public float maxSpeed             = 15F;
  9.             public bool swiming               = false;
  10.             public bool climbing              = false;
  11.             public float rotateSpeed          = 100F;
  12.             public bool checker               = false;
  13.             public Vector3 moveDirection      = Vector3.zero;
  14.             public float jumpSpeed            = 8F;
  15.             public float sprintCurHealth      = 0F;
  16.             public int sprintMaxHealth        = 50;
  17.             private int _PercentFull          = 100;
  18.             public bool isSprinting           = false;
  19.             public float gravity              = 20.0F; //set to Public
  20.             //-------------------------------------------//
  21.             private bool grounded             = false; //Had to set it to true for the script to work on its own.
  22.             static public bool allowMove      = true;
  23.             static public bool playerSneaking = false;
  24.      
  25.             void Awake (){
  26.                     sprintCurHealth = sprintMaxHealth;
  27.             }
  28.      
  29.             void Update(){
  30.                     if (isSprinting==true){
  31.                             currentSpeed = maxSpeed;
  32.             }
  33.                     else {
  34.                             currentSpeed = walkSpeed;
  35.                     }
  36.                     if (Input.GetKey("left shift") && Input.GetKey("w")){
  37.                             if (sprintCurHealth > 0){
  38.                                     isSprinting = true;
  39.                             }
  40.                             else{ //if sprintCurHealth is not more than 0, it must be equal to or smaller than 0.
  41.                                     isSprinting = false;
  42.                             }
  43.                     }
  44.                     if (sprintCurHealth > sprintMaxHealth){
  45.                             sprintCurHealth = sprintMaxHealth;
  46.                     }
  47.                     if (isSprinting==true){ //it make the script more readable if you're more specific.
  48.                             sprintCurHealth =- Time.deltaTime;
  49.                     }
  50.                     else{ //if it's not true, it must be false. You should use else here.
  51.                             sprintCurHealth =+ Time.deltaTime;
  52.                     }
  53.                     transform.Rotate(0,Input.GetAxis("Mouse X") * rotateSpeed * Time.deltaTime, 0);
  54.             }
  55.          
  56.             void FixedUpdate() {
  57.                     if (Input.GetKeyDown("q")){
  58.                             moveDirection.y = jumpSpeed;
  59.                             //animation.Play("roll");
  60.                             //Roll();
  61.                     }
  62.                     if(allowMove==true){
  63.                             if (grounded==true) {
  64.                                     moveDirection = new Vector3(Input.GetAxis("Horizontal")*currentSpeed, 0, Input.GetAxis("Vertical")*currentSpeed);
  65.                                     moveDirection = transform.TransformDirection(moveDirection);
  66.                                     moveDirection *= currentSpeed;
  67.                                     if(swiming==false){
  68.                                             if (Input.GetKey(KeyCode.Q)) {
  69.                                                     moveDirection.y = jumpSpeed;
  70.                                                     //Roll();
  71.                                             }
  72.                                             else if (Input.GetKeyDown(KeyCode.Space)) { //you don't have to check for the jump key if you're already pressing Q.
  73.                                                     moveDirection.y = jumpSpeed;
  74.                                             }
  75.                                     }
  76.                             }
  77.                             else if (climbing==true){
  78.                                     moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"),0);
  79.                                     moveDirection = transform.TransformDirection(moveDirection);
  80.                                     moveDirection *= currentSpeed;
  81.                             }
  82.                     }
  83.                     if(swiming==true){
  84.                             currentSpeed = walkSpeed;
  85.                     }
  86.                     transform.position += moveDirection;
  87.             }
  88.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement