Cant figure out how to make an object start a timer on collision

I have a piece of code that starts a timer based on fps and I need a script that will allow me to trigger this to start/stop using a collision:

var DragRace = pc.createScript('dragRace');

DragRace.prototype.initialize = function() {
   this.time = 0;
    
};


DragRace.prototype.update = function(dt) {
   this.time++;
   var time = this.time ;
    
   this.entity.element.text = time;

Hi @DeductedFlame24,

(I’ve formatted your code using the code highlight button from the compose message toolbar)

You can use a collision event to start the timer. Check the following example on how it plays a sound each time there is a collision event firing:

https://developer.playcanvas.com/en/tutorials/collision-and-triggers/

1 Like

Ok thank you I will try that

1 Like