Hey Guys,
I’m working on a Skool Project with some guys and it’s a First-Person Game. We almost got everything done, but we do only need Cooldown/Stamina for running. So, when you run the stamina goes down and when it’s empty (the bar) that you temporarily can’t run and when it’s full again you can… and so on.
So, any help would be really-Really appreciated for our project!
Here is our GameController.Js for so far,
var speed = 30.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
var jumpCount = 0;
var maxJump = 1;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
private var mainCamera : GameObject = null;
private var controller : CharacterController = null;
function Start ()
{
Screen.showCursor = false;
mainCamera = GameObject.FindWithTag("MainCamera");
controller = GetComponent(CharacterController);
}
//Reset jumpCount
function OnCollisionEnter()
{
jumpCount = 0;
}
function Update() {
if (!grounded) {
moveDirection.x = Input.GetAxis("Horizontal")*speed;
moveDirection.z = Input.GetAxis("Vertical")*speed;
}
else {
moveDirection = Vector3(Input.GetAxis("Horizontal")*speed, 0.0, Input.GetAxis("Vertical")*speed);
//reset jump because we are grounded
jumpCount = 0;
}
//jump
if (jumpCount < maxJump) {
if (Input.GetButtonDown ("Jump")) {
moveDirection.y = jumpSpeed;
jumpCount++;
}
}
moveDirection = transform.TransformDirection(moveDirection);
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
grounded = (GetComponent(CharacterController).Move(moveDirection * Time.deltaTime) & CollisionFlags.CollidedBelow) != 0;
//RUNNING
if (Input.GetKey (KeyCode.F))
speed = 50.0;
else //
speed = 30.0;
}
@script RequireComponent(CharacterController)