- Home /
Trouble toggling Raw Image script component inherited from Canvas upon mouse click
I attached a script (ClickMe) under the Raw Image container object under Canvas. My goal is to reveal/hide (toggle) the image on canvas by enabling/disabling the raw image script. I seem to have trouble re-enabling the image after disabling it.
Any clue as to why that happens would be appreciated! Thanks!
using UnityEngine; using UnityEngine.UI; using System.Collections; using UnityEngine.EventSystems;
public class ClickMe : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler {
public RawImage tileImage;
// Use this for initialization
void Start () {
tileImage = GetComponent<RawImage>();
}
// Update is called once per frame
void Update () {
// it works when I update every frame
/*
if (Input.GetMouseButtonDown (0)) {
Debug.Log ("Mouse Down");
tileImage.enabled = !tileImage.enabled;
}
*/
}
public void OnPointerEnter(PointerEventData eventData)
{
Debug.Log ("On Enter Pointer");
}
public void OnPointerExit(PointerEventData eventData)
{
Debug.Log ("On Exit Pointer");
}
public void OnPointerClick(PointerEventData eventData)
{
Debug.Log ("On Click Pointer");
tileImage.enabled = !tileImage.enabled; // Can't enable after disabled
}
}
Your answer
Follow this Question
Related Questions
How do i disable my buttons while dragging ScrollRect? 0 Answers
Touch a specific area on the screen 2 Answers
Having problems with touch input 1 Answer
PauseMenu - Camera moves in pausemenu 0 Answers
How to avoid TouchPhase.Ended effect? 0 Answers