Hi,
I’ve been trying to implement the following: when the user presses the mouse button, a cursor in the shape of a flattened sphere (this is a 2D game) appears. This cursor has an appropriate sphere collider associated with it, which is supposed to help select objects in the area of the sphere.
The objects in questions are simple boxes that hover in space, each of which has a box collider and a (kinematic) rigid body. Their box colliders are triggers. To give the impression that each object is selected, a enable a halo around the object. If it is not selected, the halo is disabled.
In a nutshell: the sphere cursor is supposed to select the box objects, each of are triggers. The sphere cursor has a “Cursor” tag, and a cursor is spawned with a single left mouseclick. One can hold the left mouse button to keep the cursor alive.
Now in the code for each box object, I do this:
function OnTriggerEnter(hit : Collider)
{
if (hit.gameObject.tag == "Cursor")
{
this.GetComponent("Halo").enabled = true;
}
}
function OnTriggerExit(hit: Collider)
{
if (hit.gameObject.tag == "Cursor")
{
this.GetComponent("Halo").enabled = false;
}
}
This looks fine, but if I quickly create the cursor and disable it (i.e. press the mouse button and let go), objects do not get de-selected (i.e. they never exit the cursor, so the halo stays enabled around them). I’ve tried OnTriggerStay to see if an object is selected while it is inside the cursor but apparently that does not get called that frequently, and the de-selection incurs a delay when an object leaves a cursor. Does anyone have any suggestions/alternatives?
FYI I am using Unity 3.3.0f4.
Thank you…