I am making a puzzle game in unity3D 5 for school and one of the puzzles is this: The player (third person) can pick up certain objects (4 objects) and has to place them inside holes in a wall in a specific order for a door to open.
I have 4 empty gameobjects named as slot001, slot002, slot003 and slot004 at the right positions at the holes in the wall. When the player has an item held and a certain button is pressed I link the transform of the object to the transform of the empty gameobject.
The problem is that the objects transform has to link to the transform of the closest gameobject. So when you stand in front of the slot002 gameobject the objects transform should link to the transform of slot002. The same goes for slot 001, 003 and 004 ofcourse. I am not sure how to do this.
I put the 4 empty gameobjects (slots) in a list. I know of the Vector3.Distance() function and I tried using that to check for the closest distance with Mathf.Min() but I couldn't quite get it to work.
Any help or a nudge in the right direction would be appreciated!