Hello,
I’m trying to fill a StackPanel with simpleButtons based on what is returned from a database.
It’s working to some extent - each button has a unique name based on the appropriate data from the retrieved object. But each button has the same behavior as the final button generated. IE when I use onPointerUpObservable to console.log the button’s uniqueId, they all return the same uniqueId. Any thoughts on what I’m doing wrong?
function makeButtons() {
var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI(
"UI"
);
var panel = new BABYLON.GUI.StackPanel();
advancedTexture.addControl(panel);
// console.log(topicBtnNames);
for (let i = 0; i < topicBtnNames.length; i++) {
var topicButton = BABYLON.GUI.Button.CreateSimpleButton(
"but",
topicBtnNames[i]
);
topicButton.width = 0.2;
topicButton.height = "40px";
topicButton.color = "white";
topicButton.background = "green";
topicButton.uniqueId = i;
advancedTexture.addControl(topicButton);
panel.addControl(topicButton);
topicButton.onPointerUpObservable.add(function() {
console.log(topicButton.uniqueId);
});
}
}