常用自制脚本:透明度统一修改
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了常用自制脚本:透明度统一修改相关的知识,希望对你有一定的参考价值。
using UnityEngine; using System.Collections; using UnityEngine.UI; /// <summary> /// User interface alpha ctrl. /// 统一控制图片的透明度 /// </summary> public class UIAlphaCtrl : MonoBehaviour { Image[] images; Text[] texts; Color[] c_Images; Color[] c_Texts; void Awake () { GetChildren (); } void GetChildren(){ images = GetComponentsInChildren<Image>(); texts = GetComponentsInChildren<Text> (); c_Images = new Color[images.Length]; c_Texts = new Color[texts.Length]; for (int i = 0; i < images.Length; i++) { c_Images [i] = images [i].color; } for (int i = 0; i < texts.Length; i++) { c_Texts [i] = texts [i].color; } } public void ChangeAlpha(float alpha){ for (int i = 0; i < images.Length; i++) { c_Images [i].a = alpha; images [i].color = c_Images [i]; } for (int i = 0; i < texts.Length; i++) { c_Texts [i].a =alpha; texts [i].color = c_Texts [i]; } } }
注意:
将目标UI归纳到一个对象下,并绑该脚本
以上是关于常用自制脚本:透明度统一修改的主要内容,如果未能解决你的问题,请参考以下文章