Question by
GuismoCabrera97 · Jun 06, 2020 at 08:22 AM ·
textureraycastandroid buildcompiler errorcolorpicker
Raycast Color Pixel Problem , It works on editor but not when compiling for Android
Hi, Im trying to raycast a object with a PNG texture (which is downloaded from a URL with UnityWebRequestTexture ); Basically I'm aiming to know whether my raycast touched a transparent point of the texture or not...
I have done this code, and I works perfecttly on unity editor but I dont know why it does not work when compiling the app for Android. Any Guess ??
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
if (hit.transform.gameObject.CompareTag("Tag"))
{
Renderer renderer = hit.transform.GetComponent<MeshRenderer>();
Texture2D texture = renderer.material.mainTexture as Texture2D;
Vector2 pixelUV = hit.textureCoord;
pixelUV.x *= texture.width;
pixelUV.y *= texture.height;
Vector2 tiling = vr_ad_material.mainTextureScale;
Color color = texture.GetPixel(Mathf.FloorToInt(pixelUV.x * tiling.x), Mathf.FloorToInt(pixelUV.y * tiling.y));
if (color.a > 0)
{
Debug.Log("TRUE);
}
}
}
}
Comment