- Home /
Increase mouseclick area size for OnMouseDown() - For Mouse Shooting Game (Open to more ideas)
I am making a shooting game where the mouse acts as the crosshair and the targets use OnMouseDown() to know when they are hit. My problem is that I do not want the mouse to click only at one pixel because that is too small of an area. Is there a way to increase the area of the mouse click? Maybe to 4x4 pixels? Or maybe I can use another method to achieve my goal?
Answer by Bunny83 · Jan 14, 2013 at 10:55 AM
Well, just increase the size of your colliders. If you don't want to increase the collider sizes you have to ray cast manually. Instead of a Raycast you can use a SphereCast and use then radius you want
I would prefer raycasting but I dont think it will work for my game since Im using a perspective camera and the ray only shoots in one direction, potentially missing anything under the mouse click due to perspective. Im trying to figure out a non mouse method so my game is more multi-platform/joystick ready but that might be worth an entirely new question.
SphereCast works well
http://answers.unity3d.com/questions/380811/can-cameraworldtoscreenpoint-be-used-to-check-if-o.html
Thanks for the help
Answer by cdrandin · Jan 14, 2013 at 10:05 AM
From looking around in the docs I found some stuff. Not sure if they work, but it wouldn't hurt to try it out. http://docs.unity3d.com/Documentation/ScriptReference/EditorGUIUtility.AddCursorRect.html
oh really? If you could confirm it so I can make note of it, thanks.
This function dose not what you want because:
- EditorGUIUtility is an editor class and can't be used at runtime. 
- AddCursorRect specifies which mouse cursor will be displayed in this area. This can be used in an editor script to change the mouse cursor for example to indicate a resize action. 
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                