- Home /
Accessing game object based on position
Hiii developers, please help this new bee. I want to access game object based on its position. How can I do this? Is it possible?
I have to make a game in which there are multiple cubes available. Cubes with same colors have to be deleted if they are attached and more than two.
I was thinking that if they are accessed as per there position i.e. current cube is red color, above cube(aboveCube.position.y == curCube.pos.y+1) is red color, left cube((leftCube.position.y == curCube.pos.y+1)) is left color and then clicked then destroy.
Actually I am unable to write what I am willing to say, but you can get if you will see the game
Answer by Piflik · Jan 04, 2013 at 09:56 PM
If you want to get the object that enters a specific area, the best way to do that would be OnTriggerEnter, with a collider specifying the area. You can compare an objects position with a certain Vector3, but if you want to get all objects that are within a certain threshold around that position, you would have to iterate through all objects in the scene, every frame (or at least in a sufficient subset of frames), and calculate their distance to the Vector3 specified, which is not very efficient.
I want to make this game
http://www.gamefools.com/onlinegames/free/supercollapsepuzzlegallery2.html
but I am not able to change the colour of similar attached boxes