1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > unity脚本控制逐渐消失_Unity实现物体逐渐消失(逐渐出现)

unity脚本控制逐渐消失_Unity实现物体逐渐消失(逐渐出现)

时间:2018-09-26 21:26:17

相关推荐

unity脚本控制逐渐消失_Unity实现物体逐渐消失(逐渐出现)

原理很简单,就是通过改变目标物体的Alpha值。但是要求材质的类型是Transparent/Diffuse

有用的地方在代码中标注了,直接贴代码

using UnityEngine;

using System.Collections;

public class Fade : MonoBehaviour

{

float tempTime;

void Start()

{

tempTime = 0;

//获取材质本来的属性

this.GetComponent().material.color = new Color(

this.GetComponent().material.color.r,

this.GetComponent().material.color.g,

this.GetComponent().material.color.b,

//需要改的就是这个属性:Alpha值

this.GetComponent().material.color.a);

}

void Update()

{

if (tempTime < 1)

{

tempTime = tempTime + Time.deltaTime;

}

if (this.GetComponent().material.color.a <= 1)

{

this.GetComponent().material.color = new Color(

this.GetComponent().material.color.r

, this.GetComponent().material.color.g,

this.GetComponent().material.color.b,

//减小Alpha值

gameObject.GetComponent().material.color.a - tempTime / 50);

}

}

}逐渐出现和这个类似,就是一开始Alpha值设置为0,然后逐渐增加

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。