Hello I have 2 scripts, my FirstPersonController.cs and my SprintLogic.cs. There’s a static class in both of them called movementSpeed, which I’m trying to change in the Sprint Logic. I have a cooldown set for 3 seconds and the sprint duration also at 3. The problem is, using Time.deltaTime isn’t helping me calculate the time passed. When I debugged it, it gave me numbers from 0.015 - 0.017. Is my code wrong? Help appreciated
Also, I’m not quite sure how to change the cooldown. I want the player to be able to sprint for 3 seconds and have a cooldown of 2. How?
SprintLogic.cs
using UnityEngine;
using System.Collections;
public class SprintLogic : MonoBehaviour {
public static float movementSpeed;
public float sprintSpeed = 10.0f;
public float sprintDuration = 3.0f;
private float sprintCooldown = 0f;
CharacterController cc; //Sets CharacterController as "cc"
// Use this for initialization
void Start () {
cc = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.LeftShift) && cc.isGrounded && sprintCooldown <= 0) {
FirstPersonController.movementSpeed *= 2;
sprintCooldown += Time.deltaTime;
}
if (sprintCooldown >= 3) { //3 = sprint duration
FirstPersonController.movementSpeed = movementSpeed / 2;
sprintCooldown -= Time.deltaTime;
}
Debug.Log("Delta time: " + Time.deltaTime);
}
}