I`m trying to add a bullet time effect to my game, but the problem is that it is constantly on when I hit the assigned key and that makes it way too easy.
I need a way of limiting the effect. It should only work for a certain time, and have a cool-down period before you can use it again.
Any ideas? And keep in mind that I`m new to scripting; my head is already raw trying to figure this yield stuff out.
You can make a simple timer by checking how much time passes by adding deltaTime each frame. You tell bullet time to stop after so many seconds has passed.
var currentBulletTimer : float = 0;
var bulletTimeAllowed : float = 3.0; // seconds
function Update () {
if (Input.GetButtonDown ("Fire2")) {
if (Time.timeScale == 1.0)
Time.timeScale = 0.3;
else
Time.timeScale = 1.0;
//Time.fixedDeltaTime = 0.02 * Time.timeScale;
}
if (Time.timeScale == 0.3) {
currentBulletTimer += Time.deltaTime;
}
if ( currentBulletTimer > bulletTimeAllowed ) {
currentBulletTimer = 0;
Time.timeScale = 1.0;
}
}