The button with the image is not pressed. The buttons in front of you are pressed even though you pressed the button in the back because the two buttons with the images are overlapped. I think the image range covers the button behind you, so how can I solve this phenomenon?
I don't know how to solve it.
CodePudding user response:
Here is your solution:
Use alphaHitTestMinimumThreshold! image settings First of all, since we're going to touch the image settings in the code, we'll set Read/Write Enabled in Advanced to true for the image. Then, write the code below and put it in the button.
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Image))]
public class CustomButton : MonoBehaviour
{
private void Start()
{
GetComponent<Image>().alphaHitTestMinimumThreshold = 0.1f;
}
}
Then you can solve this problem with just one line of code.