Hello, I am attempting to find an object from my array of objects at random and then modify its material. Currently, I have this:
var SGamemanager = pc.createScript('sGamemanager');
var shuffleObjects;
//initialize code called once per entity
SGamemanager.prototype.initialize = function() {
shuffleObjects = this.app.root.findByTag("SO");
console.log(shuffleObjects.length);
var chosenObject = shuffleObjects[Math.floor(Math.random(shuffleObjects.length - 1))];
console.log("" + chosenObject);
chosenObject.entity.model.meshInstances[0].material = new pc.Color(1,1,0,1);
pc.materials.Update();
};
I get the error that entity is undefined.
Any help would be appreciated.
I have since then figured it out. Yaustar was correct, I was referencing and changing the material as obosed to referencing the object and then updating it. Thank you very much!
I don’t think that’s necessary because every answer contributes to a solution. Even if an answer does not immediately solve the problem, it does not mean that the answer is incorrect.