Be the first to post for 'When Mouse Leaves Game Window'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

Hi,

The approach you take in the video doesn’t help for when you move over the horizon.
In my game you have a pan control of the camera meaning you can easily see around your character and therefore I found a different solution to this issue by adding;

if (hitInfo.collider == null) { return false; }

as a third line in the RaycastForEnemy method.
Is this a good solution or will it cause problems elsewhere?

2 Likes

That looks fine to me, does it play ok?

Hi Ben.
When maxDepth of Raycaster is bigger than 100f(determined in script) ,for example when player click a far area, that null reference error produce again.
I check Jane_Doe aproach and work well even in far area.
Is This a good Way?
Thanks

Thanks It worked for me

I did something very similar - but using the bool result of the raycast instead:

        bool hitAnything = Physics.Raycast(ray, out hitInfo, maxRaycastDepth);
        if (!hitAnything) { return false; } 

Seems to work ok.

1 Like

Privacy & Terms