There are a lot of posts regarding this problem in various website and even in this one but no one has given a feasible solution to this problem. I have a button that has a custom sprite. I also have a custom script attached to that button which when pressed down (IPOINTER DOWN
) changes the color of particular sprite renderer. All this works in pc but not on apk build. Why?
I have two canvas, so I thought there might be raycasting issues, so I disabled one but still no luck.
The buttons are in world space in canvas. So, I thought I might not use a canvas but IPointer
only works on clickable UI elements.
The scene looks like this, star is the clickable button and the borders are a sprite(district).
The script attached to the button is:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class OnHighlighted : MonoBehaviour, IPointerClickHandler, IPointerDownHandler// required interface when using the OnPointerEnter method.
{
// HoldByeach button
private GameObject correspondingImage;
void Start ()
{
correspondingImage = GameObject.Find(gameObject.name);
}
public void OnPointerClick(PointerEventData pointerEventData)
{
GetComponent<Image>().color = new Color32 (36,53,53,255);
correspondingImage.GetComponent<SpriteRenderer>().color= new Color32 (36,53,53,255);
}
public void OnPointerDown(PointerEventData pointerEventData)
{
GetComponent<Image>().color = new Color32 (47,255,0,255);
correspondingImage.GetComponent<SpriteRenderer>().color = new Color32 (47,255,0,255);
}
}