- Home /
OnMouseEnter "jumping" to different GameObjects
I've setup a grid of 'Tiles' in my game. Each 'Tile' is an Empty GameObject that has a 'Tile script' attached, as well as a Box Collider marked 'Is Trigger'. I've got other empty GameObject's as children of the root. In this instance it's laid out as follows:
"Floor" (empty gameobject w/ Tile script + box collider)
"floor" (empty gameobject, just acting as a container)
"normal" (empty gameobject)
"floor" (mesh, mesh renderer, and material. no colliders, marked as navigation static)
"backwards" (empty gameobject)
"floor" (mesh, mesh renderer, and material. no colliders, marked as navigation static), the only difference is this is the underside of normal > floor
The scale on each game object is 1, except the root which is 0.01.
The meshes are just planes that are 1.5x1.5 that were created in Maya. In the root game object the box collider envelopes the mesh and is extended in the height direction by a little to completely 'overwrap' the map.
The attached script has the following code:
void OnMouseEnter()
{
Debug.Log("on mouse enter pos " + name + " " + Input.mousePosition);
if (isAccessible)
{
if (status == Status.OneMove && Actions.GetAction(ActionsEnum.Move1))
{
SetFloorColor(Color.green);
}
else if (status == Status.TwoMove && Actions.GetAction(ActionsEnum.Move2))
{
SetFloorColor(Color.blue);
}
}
}
void OnMouseOver()
{
Debug.Log("onmouseover on " + name);
}
void OnMouseExit()
{
Debug.Log("on mouse exit " + name + " " + Input.mousePosition);
if (isAccessible)
UpdateFloorColor();
}
It checks a couple variables which are set to true for tiles near the player and sets the floor color based on that. When the game starts, the player prefab is generated and the main camera is moved to the player prefab and set as a child. The camera 'looks down' on the player in the middle of this grid of tiles. The grid itself are just a bunch of these Floor game objects aligned next to each other, manually placed.
The issue happens when I move the mouse close to the edge of a tile it will start jumping back and forth between the two tiles every frame, with the console giving the enter over exit on the first tile, and enter over exit on the second tile. But the mouse position stays the same. And sometimes it will give the same message to diagonal tiles when the cursor isn't anywhere near that edge, or it might skip a tiles and start switching between two tiles separated by another tile. And it will sometimes act as is my cursor is really several tiles over and as I move it, tiles that are several tiles away from the mouse will get called.
There's only one camera in the scene - I don't know what else to check for.