Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class script : MonoBehaviour {
- public float currentSpeed;
- public float walkSpeed = 6F;
- public float maxSpeed = 15F;
- public bool swiming = false;
- public bool climbing = false;
- public float rotateSpeed = 100F;
- public bool checker = false;
- public Vector3 moveDirection = Vector3.zero;
- public float jumpSpeed = 8F;
- public float sprintCurHealth = 0F;
- public int sprintMaxHealth = 50;
- private int _PercentFull = 100;
- public bool isSprinting = false;
- public float gravity = 20.0F; //set to Public
- //-------------------------------------------//
- private bool grounded = false; //Had to set it to true for the script to work on its own.
- static public bool allowMove = true;
- static public bool playerSneaking = false;
- void Awake (){
- sprintCurHealth = sprintMaxHealth;
- }
- void Update(){
- if (isSprinting==true){
- currentSpeed = maxSpeed;
- }
- else {
- currentSpeed = walkSpeed;
- }
- if (Input.GetKey("left shift") && Input.GetKey("w")){
- if (sprintCurHealth > 0){
- isSprinting = true;
- }
- else{ //if sprintCurHealth is not more than 0, it must be equal to or smaller than 0.
- isSprinting = false;
- }
- }
- if (sprintCurHealth > sprintMaxHealth){
- sprintCurHealth = sprintMaxHealth;
- }
- if (isSprinting==true){ //it make the script more readable if you're more specific.
- sprintCurHealth =- Time.deltaTime;
- }
- else{ //if it's not true, it must be false. You should use else here.
- sprintCurHealth =+ Time.deltaTime;
- }
- transform.Rotate(0,Input.GetAxis("Mouse X") * rotateSpeed * Time.deltaTime, 0);
- }
- void FixedUpdate() {
- if (Input.GetKeyDown("q")){
- moveDirection.y = jumpSpeed;
- //animation.Play("roll");
- //Roll();
- }
- if(allowMove==true){
- if (grounded==true) {
- moveDirection = new Vector3(Input.GetAxis("Horizontal")*currentSpeed, 0, Input.GetAxis("Vertical")*currentSpeed);
- moveDirection = transform.TransformDirection(moveDirection);
- moveDirection *= currentSpeed;
- if(swiming==false){
- if (Input.GetKey(KeyCode.Q)) {
- moveDirection.y = jumpSpeed;
- //Roll();
- }
- else if (Input.GetKeyDown(KeyCode.Space)) { //you don't have to check for the jump key if you're already pressing Q.
- moveDirection.y = jumpSpeed;
- }
- }
- }
- else if (climbing==true){
- moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"),0);
- moveDirection = transform.TransformDirection(moveDirection);
- moveDirection *= currentSpeed;
- }
- }
- if(swiming==true){
- currentSpeed = walkSpeed;
- }
- transform.position += moveDirection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement