Search code examples
c#imagebuttonunity-game-enginetransparency

How to Change transparency of button image in Unity 5.0?


I would like to change the transparency of button image from the script (written in C#). What is the best way to do it?


Solution

  • Here the script version!

                using UnityEngine;
                using System.Collections;
                using UnityEngine.UI;
    
                public class SetTransparancy : MonoBehaviour {
                    public Button myButton;
                    // Use this for initialization
                    void Start () {
                        myButton.image.color = new Color(255f,0f,0f,.5f);
                    }
    
                    // Update is called once per frame
                    void Update () {
    
                    }
                }
    

    I tested it in Unity5