- Home /
"alphaHitTestMinimumThreshold" and "Sprite.Create" Issue
Hello, First thing Try this script:
using UnityEngine;
using UnityEngine.UI;
public class testscript : MonoBehaviour {
public Texture2D Tex;
void Start () {
GetComponent<Image> ().sprite = Sprite.Create (Tex, GetComponent<Image> ().sprite.rect, new Vector2 (0.5f, 0.5f));
GetComponent<Image>().alphaHitTestMinimumThreshold = 0.1f;
}
}
add this script to your button gameobject (without text child)
place an alpha image to Texture2D
place this alpha image to the button image component too
make the Texture2D image readable in import settings
-------------------------------------------
now click play you'll see the button has issues with cursor & wrong position! is there any way to fix this ? i'm using the version 5.6.1f1
Comment
The way you phrased this question makes me think of when I was a kid and other kids would tell me to put my hand in front of my face.
Best Answer
Answer by Vadol · Nov 04, 2017 at 07:49 AM
nevermind I solved it !
the issue is that Sprite.Create 'was' set to Tight MeshType all what I needed is changing the MeshType to "Full Rect"
GetComponent<Image> ().sprite = Sprite.Create (Tex, GetComponent<Image> ().sprite.rect, new Vector2 (0.5f, 0.5f),100,0,SpriteMeshType.FullRect);