- Home /
Question by
smeagols · Oct 29, 2014 at 08:37 PM ·
variableinvokerepeating
[closed] problem with invokerepeating and public variable
hi,
i have this code:
public var state:int;
private var startTimer = false;
private var time = 4;
function Update()
{
... ...
if (state == 6)
{
if (!startTimer)
{
InvokeRepeating("Timer", 0, 1);
startTimer = true;
}
}
... ...
function Timer()
{
if (--time <= 0)
{
Debug.Log("i'm here");
state = 7;
CancelInvoke("Timer");
}
}
he point is... the invokeworks ok. it make a countdown from 4 to 0 and print "i'm here" and cancelInvoke. But state continue = 6
what i'm doing wrong? Thanks
Comment
Answer by MrSoad · Oct 29, 2014 at 08:45 PM
Try this :
// JavaScript Document
public var state : int;
private var startTimer : boolean = false;
private var time : int = 4;
function Update() {
if (state == 6) {
if (!startTimer) {
InvokeRepeating("Timer", 1, 1);
startTimer = true;
}
}
}
function Timer() {
time = time - 1;
if (time <= 0) {
Debug.Log("i'm here");
state = 7;
CancelInvoke("Timer");
}
}
thanks, i find the problema out this code, i forcé state to 6 at other part of code :(((
Your answer
Follow this Question
Related Questions
Variable bug??? 0 Answers
Communication between objects and other scripts, variables and properties 1 Answer
Rewind/Play animations on demand. 1 Answer
Can I show a numeric variable from the slider on the GUI? 1 Answer
variable inside prefab 1 Answer