- Home /
Javascript Timescale Problem
The problem i am having is that i have a script that is attached to these blocks that are falling and i have a certain "Power-up" block that will slow time. The problem is that when you click the block it disappears and is supposed to put the Time.timeScale to 0.1 but does not. I have put the Debug.Log in the code to see if the values change and they do but i do not see any difference when playing the game...
NOW FOR THE CODE!
Script 1: Click
var istimeslow : boolean = false;
private var timer : float = 0.0;
private var timed : float = 30.0;
static var weakblock : boolean = false;
function Update(){
if(timer >= timed){
Destroy(gameObject);
}
if(clickpoints >= 2 && weakblock == true){
clickpoints -= 1;
}
}
function OnMouseDown() {
timesclicked += 1;
if(timesclicked >= clickpoints){
if(istimeslow == true){
TimeSlowScript.slowtime = true;
}
GuiHandler.score += scorepoints;
GuiHandler.money += moneyvalue;
Destroy(gameObject);
}
}
function OnCollisionEnter(hit : Collision){
if(hit.transform.name == "Collider"){
Destroy(gameObject);
GuiHandler.currenthp -= damage;
}
}
Script 2: TimeSlowScript
private var timer : float = 0.0;
private var timed : float = 5.0;
static var slowtime : boolean = false;
function Update() {
if(slowtime == true){
Time.timeScale = 0.1;
Debug.Log("" + Time.timeScale);
timer += Time.deltaTime;
if(timer >= timed){
slowtime = false;
Time.timeScale = 1;
Debug.Log("" + Time.timeScale);
timer = 0.0;
}
}
}
I have tested your script and it works as i think it should. I made the static boolean a normal public var and i'm triggering it "manually". When I turn it "on", everything slows down for 50 sec. like expected. After 50 sec. it goes back to normal.
It seems to not do that with me i set the timed variable in the TimeSlowScript and when i click the block and destroy it i see in the debug console that it goes to .1 but almost instantly goes back to 1... is there anything that could conflict with me changing the timescale? Thanks.
Perhaps there is another script in your level that is also trying to change the timescale?
Your answer
Follow this Question
Related Questions
Help with my "speeding up time" script 1 Answer
Pause button 2 Answers
Times and difference 1 Answer
Lots of !IsFinite() Errors and FPS crawling to a halt - How to debug? 1 Answer