I have created a very rudimentary slow motion ability in my game but I don’t want it to be able to be used at all times.
The solution I have in my head the idea is to have a SlowMotionCredit bank which depletes with usage at a fast rate and then slowly replenishes itself.
The following code is attached to the ‘player’ but once I add the SlowMotionCredit related lines the script compiles on but the slowmotion then doesn’t work… Interesting to hear people’s thoughts… cheers
var xspeed : float = 5;
var zspeed : float = 5;
var x : float;
var z : float;
public var SlowMotionCredit : float = 60; // SlowMotionCredit Initial starting figure
function Update () {
x = Input.GetAxis("Horizontal") * xspeed * Time.deltaTime;
z = Input.GetAxis("Vertical") * zspeed * Time.deltaTime;
transform.Translate(x, 0, z);
SlowmotionCreditUpdate() {
SlowMotionCredit +1; // replenish SlowMotionCredit at a rate of 1 per second
}
//SlowMotion Starts
if (Input.GetKeyDown ("space"))
Time.timeScale=0.15;
SlowMotionCredit - 12; // Deducting 12 Credits for each second of SlowMotion Time Spent
//Time resets
if (Input.GetKeyUp ("space"))
Time.timeScale=1;
}