- Home /
OnMouseOver with 2 overlapping object not working properly
Hi, I'm making a prototype game that when I click on the white box it will turn green, and when I click brown circle it will turn red. It works properly when it's separate from each other but doesn't work properly when they overlap. When I click on white box it makes brown circle turn red but the box doesn't change color
My gameObject have Sprite Renderer + Collider + Script
I also tried to order them in layers but it doesn't help.
This is white box script
void OnMouseOver()
{
if (Input.GetMouseButton(0))
{
GetComponent<SpriteRenderer>().color = Color.green;
Debug.Log("Line");
}
}
This is brown circle script
void OnMouseOver()
{
if (Input.GetMouseButton(0))
{
GetComponent<SpriteRenderer>().color = Color.red;
Debug.Log("Cookie");
}
}
PS. Sorry if my grammar is not correct. English is not my native.
PS2. I'm also new to Unity T^T
Your answer
![](https://koobas.hobune.stream/wayback/20220613045539im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Collider not registering hits? 4 Answers
Object not responding to OnTriggerEnter() 2 Answers
How Do I Make My Weapon Follow My Cursor? 0 Answers
Help with 2d TowerDefense Game 2 Answers
Endless Runner Game: Turn Corners 0 Answers