not exactly sure if it belongs in this channel, but it probably does
i'm working on a crosshair system where the crosshair only appears when you're hovering over an object that can be interacted with. everything was fine until i remembered to add a check to make sure you were close enough to the object in order to use it.
now, for some reason, when i hover over an object, it doesn't detect i've done so. only when i stand still, hover off the object, and hover back on, does it detect properly, and if i move around, it fails again
code is right here (still new to using c# but i think this belongs here over the beginner channel)
`void OnMouseEnter()
{
float dist = Vector3.Distance(this.gameObject.transform.position, camera.transform.position);
if (dist < minDist)
{
//these two following lines work fine on their own without the distance check
isHover = true;
chAnim.Play("Base Layer.CrosshairIn", 0, 0f);
}
}
void OnMouseExit()
{
float dist = Vector3.Distance(this.gameObject.transform.position, camera.transform.position);
if (dist < minDist)
{
//as well as these two
isHover = false;
chAnim.Play("Base Layer.CrosshairOut", 0, 0f);
}
else
{
//so that it doesnt play the fade out animation whenever you hover off anything
isHover = false;
}
}`



but i'll have a look at that repo, seems pretty nice!