- Home /
The question is answered, right answer was accepted
How do I compare the position of my player to each elements position of an array of GameObjects?
Hi, I have a character that moves up,down,left and right using arrow keys (Tile based) but there are some position the player is not allowed to go. I have set up 24 empty GameObjects on the map so that I can compare the players position with one of the empty GameObjects. ( the 24 position being where the player is not allowed to go)
I made an array with the 24 empty GameObjects in it.
My question is : How do I compare the position of the player with each elements position ? Meaning if my player is on the same position as one of the empty GameObjects in that array it should run my function Death();
Oh never$$anonymous$$d ! I found the solution :)
this is the code I use after I press on one of the arrow keys :
foreach(GameObject data in TheArrayiUsed){
if(data.transform.position== this.transform.position){
death();
}
}