Hello, I have a super weird problem that I have only found a few other people having. The pages I have found of others having the problem didn’t get answered. Some were even lead to believe it was corrupt.
My problem is I have a set of functions that freeze specific objects in the scene for the set amount of time, then unfreezes them. I have a check in the same script as the functions, where anytime i press the “K” key, it calls the function. It works perfectly. It calls it, freezes them, and after the specified time, it unfreezes them. BUT when I call that EXACT same function from a separate script it doesn’t work, not entirely anyway. It will call the function, it freezes the objects, sets the timer, but for some really weird reason, doesn’t count down. Instead they just stay frozen forever.
Here is the code, any help would be awesome. Thanks. This is the GameControllerScript. It has the functions and keypress function call.
function Update{
if (Input.GetKeyDown(KeyCode.K)){
FreezeBallsForTime(5);
}
if (Level.freeze){
if (ballsFreezeTimer > 0){
ballsFreezeTimer -= Time.deltaTime;
if (ballsFreezeTimer <= 0){
Level.UnFreezeBalls();
}
}
}
}
function FreezeBallsForTime( waitTime : float ){
if (Level.freeze == false){
Level.FreezeBalls();
Debug.Log("ballsFreezeTimer " + ballsFreezeTimer);
ballsFreezeTimer = 5;//waitTime;
}else if (Level.freeze){
ballsFreezeTimer += waitTime;
}
}
public class Level
{
public static var freeze : boolean = false;
public static function FreezeBalls(){
if (freeze == false){
Debug.Log("FreezeBalls() Called");
freeze = true;
}
}
public static function UnFreezeBalls (){
Debug.Log("UnFreezeBalls() called");
freeze = false;
}
}
And then in the player script
function ActivateFreeze( time : float ){
gameControllerScript.FreezeBallsForTime(time); //This is referencing the first script. It will call the script fine, and it freezes the balls, but the timer goes all screwy only when not called from the GameControllerScript.
}