我想从脚本中更改按钮图像的透明度(用C#编写)。最好的方法是什么?
答案 0 :(得分:3)
这是脚本版本!
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 () {
}
}
我在Unity5中测试过它
答案 1 :(得分:1)
你试过这个,这可以解决你的问题
http://answers.unity3d.com/questions/46158/how-to-create-a-transparent-button.html
很抱歉(你是对的4等),
您可以转到按钮选择图像的颜色或正常颜色,然后在设置颜色的位置,如果将其设置为125,则可以设置alpha,然后按钮上有透明度
答案 2 :(得分:1)
您可以直接修改color属性
var color = button.targetGraphic.color;
color.a = 125; //higher than 0 otherwise it is invisible
button.targetGraphic.color = color;
button.targetGraphic.CrossFadeAlpha(0, 1, false);