I made a project a while ago following this same logic for fading. But for some reason it doesn’t work now!
Not sure the case, but here is the code, is there an updated way to handle this that I’m missing?
var FadeBlankScreen = pc.createScript('fadeBlankScreen');
FadeBlankScreen.prototype.initialize = function() {
this.timer = 0;
this.fadeOut = 0.999;
this.fadeSpeed = 0.3;
};
FadeBlankScreen.prototype.update = function(dt) {
this.timer = this.timer + dt * this.fadeSpeed;
var meshInstances = this.entity.model.meshInstances;
var alpha = this.fadeOut - this.timer; //I've also tried lerping and same problem.
// the time to fade
meshInstances[0].material.setParameter("material_opacity", alpha);
meshInstances[0].material.update(); //I also tried leaving this line of code out and still doesn't work.
console.log(alpha);
//Destroy after fade is done.
if(this.timer >= 1.1){
this.entity.destroy();
}
};