I have multiple objects in my static group and need to know which one I am colliding with when my player hits one of the objects. My code looks like this:
//Create Function
signs = this.physics.add.staticGroup()
sign1 = signs.create(0, -100, "sign1")
sign1.name = "sign1";
sign1Info = this.add.image(0, -100, "sign1").setScale(4);
sign1Info.visible = false;
sign2 = signs.create(100, -100, "sign2")
sign2.name = "sign2";
sign2Info = this.add.image(100, -100, "sign2").setScale(4);
sign2Info.visible = false;
this.physics.add.collider(player, signs){
signName = sign.name; //The info I need to get out
});
I tried this:
this.physics.add.collider(player, signs, function (sign){
signName = sign.name;
});
but when I printed the sign.name to the console it was an ’empty string’
How can I find the specific object the player is colliding with?