var from = this.camera.getPosition();
var to = from.clone();
to.add(this.camera.forward.clone().scale(10));
app.systems.rigidbody.raycastFirst(from, to, function (result) {
if(result.entity.name === "blockTop" || result.entity.name === "blockBottom" || result.entity.name === "blockRight" || result.entity.name === "blockLeft" || result.entity.name === "blockFront" || result.entity.name === "blockBack"){
target = result.entity.getParent().findByName("Test Block");
//Here is where the code to lower the blocks health should go...
}
});
Each block is surrounded by six entities which act as the sides of the block. When one of the sides is hit, the target value is set to the actual block itself. Each block should also have a script telling it how much health is should have. As the player attacks the block, it should start loosing health. The problem is I do not know how to get the health value out of the blocks script.
I have tried:
var blocksHealth = target.script.Block.blockHealth;
//When block is struck by raycast:
blocksHealth -= 1;
if(blocksHealth <= 0){
target.destroy();
}
And on the script āBlockā located on the block itself, in the āinitializeā section:
var blockHealth = 100;
It gives me an error:
cannot read property blockHealth of undefined.
What am I doing wrong?