TonyC
TonyC

Reputation: 45

Run function every 3 seconds

I need to find the position of an object every 3 seconds. This code constantly gets the position of the object. What am I doing Wrong?

function checkpoint (){
    last_checkpoint_X = player.transform.position.x;
}
function Update(){
    InvokeRepeating("checkpoint", 10, 3.0);
}

Upvotes: 0

Views: 661

Answers (2)

williamcodes
williamcodes

Reputation: 7236

It looks like you're trying to use the Unity3D MonoBehaviour.InvokeRepeating function. Try this:

function Checkpoint () {
  Debug.Log("repeating the Checkpoint function");
}

InvokeRepeating("Checkpoint", 10, 3.0);

Let us know if you get that message in your logs every 3 seconds.

Upvotes: 1

George Lica
George Lica

Reputation: 1816

Use window.setTimeout API. For more details search on google

Upvotes: 0

Related Questions