YES! THANK YOU @trollingchar.
I added the code to a script and attached the script to the button.
that is exactly the functionality i was looking for.
check out the link to the code:
https://forum.unity.com/threads/none-rectangle-shaped-button.263684/#post-2146709
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(RectTransform))]
[RequireComponent(typeof(Image))]
public class RaycastMask : MonoBehaviour, ICanvasRaycastFilter
{
private Sprite _sprite;
void Start ()
{
_sprite = GetComponent<Image>().sprite;
}
public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
{
var rectTransform = (RectTransform)transform;
Vector2 local;
RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform) transform, sp, eventCamera, out local);
// normalize local coordinates
var normalized = new Vector2(
(local.x + rectTransform.pivot.x*rectTransform.rect.width)/rectTransform.rect.width,
(local.y + rectTransform.pivot.y*rectTransform.rect.height)/rectTransform.rect.width);
// convert to texture space
var rect = _sprite.textureRect;
var x = Mathf.FloorToInt(rect.x + rect.width * normalized.x);
var y = Mathf.FloorToInt(rect.y + rect.height * normalized.y);
// destroy component if texture import settings are wrong
try
{
return _sprite.texture.GetPixel(x,y).a > 0;
}
catch (UnityException e)
{
Debug.LogError("Mask texture not readable, set your sprite to Texture Type 'Advanced' and check 'Read/Write Enabled'");
Destroy(this);
return false;
}
}
}
for those that are too lazy to follow the link :)
here is the code snippet.
It was posted by @senritsu
if i could hug you right now i would :)
ICanvasRaycastFilterinterface to override where raycast hit and where doesn't. \$\endgroup\$