总体思路:使用UGUI中图片的alpha值来控制镜头淡入淡出。默认图片的alpha值为1,只需要递减为0即可。淡入淡出方法相反即可。
首先用新建一个UGUI的图片名为:Imagealpha,颜色自定义(本文中为黑色)。如图:
将 图片 锚点设置为全屏,按键alt+鼠标 点击锚点 位置:如图:
将下面代码绑定到该图片上:
代码源码:将alpha值进行递减,直到为0
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Alphachange : MonoBehaviour {
private float alphavalue=1f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//alpha值递减
alphavalue -= 0.01f;
if (alphavalue <= 0)
{
alphavalue = 0;
}
Debug.Log(alphavalue);
this.GetComponent<Image>().color=new Color(0,0,0,alphavalue);
}
}
实现效果如图: