- Home /
How to Set a cut off point where I cant click on my object
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?
Answer by JChilton · Sep 17, 2012 at 08:34 PM
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
}
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Material doesn't have a color property '_Color' 4 Answers
Having Problem With Performing Collison with two prefab object. 1 Answer