I have a function:
function Activate()
{
...
}
How i can call the function Activate one time in the Update? In javascript please.
function Update()
{
Activate() // Once time only
}
Thank you!
I have a function:
function Activate()
{
...
}
How i can call the function Activate one time in the Update? In javascript please.
function Update()
{
Activate() // Once time only
}
Thank you!
var onetime = false;
Update()
{
if (!onetime)
{
Activate();
onetime = true;
}
}
you could call Invoke() too, if u want some delay before calling ur Activate() function.
like this
void Update()
{
// it will call Activate function after 1 sec.
if (!onetime)
{
Invoke(“Activate”, 1.0);
onetime = true;
}
}
Update() fires on every frame. You wouldn’t even want that If() statement in there.
Instead, use the Start() function – it only fires when the script starts.
function Start()
{
// This is only called once
}
function Update()
{
// This is called every frame
}
no problem, happy to help
– DaveAAlso Awake() can be used
– DaveATrue that! Just yesterday I answered someone looking to do 'start' after a delay, which is where my head was at answering this one. Presumably there would be an additional condition, like if (!onetime && some_important_other_thing_happened)
– DaveAStart() is called at the very begining, just before the first Update() call
– anon19470065