Player health script

1. function Update ()

2. {

* if(Health <= 0)

3. {

4. Die();

5. }

* if(Health >=101)

6. {

7. Health = 100;

8. }

* // missing }

* function Die() // this function is currently inside update()

9. {

10. GameObject.Destroy();

11. }

* } // extra }

Will this script work?

Not exactly, but this should.

var MyScript = pc.createScript('myScript');

MyScript.attributes.add('Health', {
    type: 'number',
    default: 100
});

MyScript.protype.Die = function() {
  // Do something here
};

MyScript.prototype.update = function(dt) {
  if (this.Health <= 0) {
    this.Die();
  } else if (Health > 100) {
    this.Health = 100;
  }
};
2 Likes

can I add you to my game as read and write, or admin to help with coding?

Frankly, I don’t have much time between work and organization duties, sorry.

1 Like