How to make a button unclickable when alpha = 0
This is my code at the moment but it doesn't work.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class UclickableButton : MonoBehaviour {
public Button button;
void Update()
{
if (Color.alpha = 0)
{
button.interactable = false;
}
if (Color.alpha = 1)
{
button.interactable = true;
}
}
}
How can I make it work?
Comment
Best Answer
Answer by Jessespike · Nov 26, 2015 at 05:07 PM
Color.alpha won't work. You must specify which Color object you are referring.
Color color = GetComponent<UnityEngine.UI.Image>().color;
The syntax to do a comparison is double equals sign. A single equal sign assigns values.
Change
if (Color.alpha = 0)
To
if (color.alpha == 0)
or
if (color.a.Equals(0))
The "if (color.alpha ==0)" doesn't seem to work though :/ the other one did though, thanks!