Unity/잡학 사전

[Unity/UI] 버튼 영역 설정 - 다양한 모양 대응

sorry0101 2022. 10. 6. 10:25

alphaHitTestMinimumThreshold 를 사용해서 raycast가 가능한 alpha값을 조절하는 것

using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.

public class ExampleClass : MonoBehaviour
{
    public Image theButton;

    // Use this for initialization
    void Start()
    {
        theButton.alphaHitTestMinimumThreshold = 0.5f;
    }
}

 

 

1로 설정하게 될 경우, 완전 불투명한 pixel만 선택 가능하게 된다.

 

완전 꿀팁인듯!


참고

https://sensol2.tistory.com/35

 

[Unity] 버튼 영역 모양 바꾸기 (세모, 사다리꼴, 그 어떤 모양도 가능)

유니티를 사용하다보면 모양이 있는 버튼을 만들어야 할 때가 생긴다. 위 사진의 경우 직사각형 모양으로 된 버튼들이 서로 겹쳐있어서 클릭이 되지 않는 경우가 발생한다. 버튼을 이미지 영역

sensol2.tistory.com

https://docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.Image-alphaHitTestMinimumThreshold.html

 

Unity - Scripting API: UI.Image.alphaHitTestMinimumThreshold

Alpha values less than the threshold will cause raycast events to pass through the Image. An value of 1 would cause only fully opaque pixels to register raycast events on the Image. The alpha tested is retrieved from the image sprite only, while the alpha

docs.unity3d.com