I’m setting up a collectables sort of game and I have been doing a little collision detection so when I click on my note that I want to collect it recognises it. However I can click on my note from 100 meters away! how do I make it so I have to be within a certain distance for example 2-3 feet until it will recognise me clicking on it?
If you’re using raycasting you can set the maximum distance for the cast.
C#
RaycastHit rInfo; //used for checking what the raycast hits
float maxDistance = 3; //in meter units
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),out rInfo,maxDistance)){
if(rInfo.collider.CompareTag("objectTag")){
//do stuff
}
}