Hi, I’m trying to do EAT coin + coin regeneration.
my way to make coin disappear is to use this.entity.destroy().
But I don’t know how to make it showup like regeneration.
Is there any solution or function to solve it ? Or using destroy() to make it disappear is the wrong way ? Any tips or sample project thanks.
@Albertos
I got some issue so more question please.
if I using this.entity.enabled = false; to make it disappear
and after that using this.entity.enable = true; to make it enable.
Will initialize function run again after enabled ?
@Albertos
I found this.entity.enabled = true; will not make my coin appear.
So what I had think about is… I have many coin entity named Coin (all same) and all Coin entity has same script named coin.js
will that be the problem to control entity to enable = true/false ?
Sorry for private project… Or maybe I can make a sample to test it and linked it to here.
@11144, this.entity.enabled = true; will make that entity enabled. If you have implemented any functionality in initialize and it’s not working on enabling again then you can use onEnable functionality of script to perform particular functions there:
Rotate.prototype.initialize = function () {
this.on("enable", function () {
this.startingFunctionalities();
});
this.startingFunctionalities();
this.on("disable", function () {
this.entity.enabled = false;// etc
});
};
Will this.entity.enabled = true; call this.on(“enable”, function() { ?
Or you are just giving me an example so I need to call “enable” using app.fire like ?
this.entity.enabled = true; calls the enable function of that script. If that script is enabled for the very first time then only initialize function will be called and enable function will not called. And after that, on every time, when the entity is enabled, only it’s onEnable function will be called.
But I got another question.
If I Duplicate an entity in HIERARCHY. Will GUID be same with original one?
Because I found guid is duplicating between two entity (same Naming) but some other same naming was not.
Well my solution is below. And I think this will be helpful for everyone.
when I disable it once, this.entity is no longer exist.
So that’s the reason why this.entity.enabled = true; doesn’t work.
For Solution, I copied guid to global, and restore it inside update function and it is doing well.