Question by
remingtonlewis2000 · May 11 at 12:45 PM ·
c#inputunity 2dtriggers
Unity Input.GetMouseButtonDown(0) not working
I am attempting to have some moving targets in my game. I have them set to destroy themselves when they get clicked on. However this only works about a third of the time?
The triggers work without the && Input.GetMouseButtonDown(0)
. they'll all destroy themselves right away. however when I add that line of code usually the first I click on will destroy right away then the other 2 wont without multiple more clicks and sometimes not at all.
Sometimes I'll give up clicking on one of them and test a different one and the one I was just clicking on will destroy
here is the code
void FixedUpdate()
{
transform.Translate(userDirection * movespeed * Time.deltaTime);
}
void OnTriggerStay2D(Collider2D collision)
{
GameObject collisionGameObject = collision.gameObject;
if (collisionGameObject.name == "aim" && Input.GetMouseButtonDown(0))
{
Destroy(gameObject);
}
}
Any help greatly appreciated
Comment