Mouse Clicks Stop After X# of clicks
Having an issue with mouse clicks which register when I first start a scene, but stop soon there after.
Set up:
2D project Sprite w/ 2D BoxCollider (Is Triggerable) Straightforward DO Something Script (At bottom)
Click #1 - All is well - new object created
Click #2 - All is well - new object created
Click #3 - All is well - new object created
Click #4 - All is well .
Click #5 - nothing... nothing and more nothing
I've tried using both OnMouse, and Update -> RayCast ... both with the same result, mouse clicks stop after a certain number of clicks.
Help would be appreciated, Many thanks.
Quick Note - Forgot to mention -- If while mouse is not working I go back into the unity editor and DELETE the first 4 Clones instantiated, I can click 4 more times... then it stops again. Rinse Repeat.
/*
void OnMouseDown()
{
if (Input.GetMouseButtonDown(0))
{
var newGO = (GameObject)Instantiate(Resources.Load("PreFabs/HorseCart")); ;
}
}
*/
public void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector2 mousePosition = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hitCollider = Physics2D.Raycast(mousePosition, Vector2.zero, Mathf.Infinity);
if (hitCollider && hitCollider.collider == ME)
{
var newGO = (GameObject)Instantiate(Resources.Load("PreFabs/HorseCart")); ;
}
}
}
After deleting, restarting re-adding everything in every combination imaginable - I believe I've narrowed down the problem to the 2D BoxCollider.
If I remove all the 2D BoxCollider and use a plain ole regular BoxCollider there "appears" to be no issue.
So...ok... 2D project + Code + 2D Assets + 3D BoxCollider = Work... 2D project + Code + 2D Assets + 2D BoxCollider = mouse throws a fit?
I thought for 2D project with 2D sprites and 2D everything that one was "supposed" to use 2D components?
Your answer
![](https://koobas.hobune.stream/wayback/20220612040058im_/https://answers.unity.com/themes/thub/images/avi.jpg)