- Home /
Dual Timer Problems
Hello,
I have a script that I am working on that has a counter to enable an object however I can't find a way to make it object specific. As soon as the awake function is called the timer starts and I tried to connect it to and empty that connected to a timer as well a timer script as well but it won't disable object and shows no errors. My goal is to have perks that can be deactivated on touch and self timer reactivates it.
Here is the Script timer I am trying to create to work for individual object and children:
var perk1 : GameObject;
var perktimer1 : int;
function Awake (){
perk1.active = false;
}
function Update () {
perktimer1++;
guiText.text = "Grow time: "+perktimer1;
if (perktimer1 > 400){
perk1.active = true;
}
}
Answer by hathol · Jun 25, 2012 at 10:22 PM
I'd add the script to the Perk object itself and then use invoke ( http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Invoke ) for the reactivation. So something like this:
var isActive:bool
function Start()
{
isActive = true;
}
function UsePerk()
{
//do stuff
isActive = false;
Invoke("Reactivate", 10); // call the function Reactivate after 10 seconds
}
function Reactivate()
{
isActive = true;
}
Thanks $$anonymous$$, this is what I was looking for with way less script involved in the long run. Others may need to know that var isActive: boolean; may be required if i'm not mistaken in some cases. Cool thanks again $$anonymous$$.
Your answer
Follow this Question
Related Questions
How to change between scripts on trigger? 2 Answers
Timer gets executed in the wrong scene 1 Answer
Time Counter - up 6 Answers
counter but with textures? 1 Answer
countdown/countup timer 1 Answer