首先在Unity中准备好8张图片,也可以其他数量的图片,最好的是这几张图片都是从一张图片分割下来的,能确保这几张图片重新拼回原来的图片。首先在场景中新建一个名WindowShades的C#脚本,并把该脚本随便挂载场景中一个激活的游戏物体上,然后打开脚本,并复制以下的代码!!!
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
public class WindowShades : MonoBehaviour {
public bool isAmount; //用来触发是否开始运动
public float fillAmount_01 = 0; //四张图片的初始值为0
public float fillAmount_02 = 0.45f; //四张图片的初始值为0.45
public GameObject Text_UI; //图片显示完毕后显示文字
public Image[] image_Go_01; //间隔的四张图片
public Image[] image_Go_02; //间隔的四张图片
public GameObject Button_UI; //图片显示完毕后显示按钮
void Start () {
InIt_WHT();
isAmount = true;
}
void Update()
{
Image_WHT();
}
private void Image_WHT()
{
if (isAmount) {
fillAmount_01 += Time.deltaTime / 10;
fillAmount_02 += Time.deltaTime / 10;
for (int i = 0; i < image_Go_01.Length; i++) {
image_Go_01[i].fillAmount = this.fillAmount_01;
if (i > image_Go_01.Length) {
i = 0;
}
}
for (int i = 0; i < image_Go_02.Length; i++) {
image_Go_02[i].fillAmount = this.fillAmount_02;
if (i > image_Go_02.Length) {
i = 0;
}
}
if (fillAmount_01 >= 0.55f)
{
Text_UI.SetActive(true);
Button_UI.SetActive(true);
this.isAmount = false;
}
}
}
private void InIt_WHT()
{
for (int i = 0; i < image_Go_01.Length; i++) {
image_Go_01[i].fillAmount = fillAmount_01;
}
for (int i = 0; i < image_Go_02.Length; i++) {
image_Go_02[i].fillAmount = fillAmount_02;
}
}
}
然后保存该脚本,并把需要赋值的游戏物体在Inspector属性面板中进行赋值(数组中图片的数量可以随意),然后运行游戏,在这里要注意的是要把形成百叶窗效果的图片设置成如下的参数!
Inspector属性面板中进行赋值的游戏物体:
形成百叶窗效果的图片要设置的参数(注意Fill Origin的方向):
最后你就会看到图片就像是几张图片共同孔雀开屏一样的而效果从而形成一张大图片,感觉非常的好看!!!