Hey all,
I posted awhile ago about making a toggle switch but have decided to implement it from scratch. Right now I’m trying to swap the background image which acts as the button but whenever I swap the texture I get a white rectangle and no errors in the console. Is this just a simple code error? This feel like a silly thing to be making a post about because I know it is extremely simple but I have yet to find the solution.
Here is the code:
var ToggleUi = pc.createScript('toggleUi');
ToggleUi.attributes.add('offTex', { type: 'asset', assetType: 'texture' });
ToggleUi.attributes.add('onTex', { type: 'asset', assetType: 'texture' });
// initialize code called once per entity
ToggleUi.prototype.initialize = function() {
this.isOff = true;
this.entity.button.on('touchend', this.toggle);
};
ToggleUi.prototype.toggle = function() {
if(this.isOff){
console.log("toggle on");
this.isOff = false;
this.entity.element.texture = this.onTex;
}
else{
console.log("toggle off");
this.isOff = true;
this.entity.element.texture = this.offTex;
}
};
And here is what it looks like before clicking it:
And then here it is after doing the swap:
Thanks in advance.