【发布时间】:2017-09-28 11:27:15
【问题描述】:
我希望我的问题没有重复; 我的团结有问题。 我为对象的透明度(淡入/淡出循环)编写了一个类。它工作正常。 我在场景中放了两个按钮。它们在画布位置。 运行后,即使我在画布中编写了一个透明对象的命令,里面的所有东西都进入透明状态(淡入淡出循环)。 我不知道。 请帮忙。
我的班级
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Threading;
using System;
public class Transparent : MonoBehaviour {
private float duration = .7f;
public float waitTime;
IEnumerator co2;
// Update is called once per frame void
public void start_tranparecncy()
{
this.co2=this.blink();
this.StartCoroutine (this.co2);
}
IEnumerator blink() {
//Color textureColor = this.transform.GetComponent<SpriteRenderer> ().material.color;
Color textureColor = this.transform.GetComponent<Image>().material.color;
//textureColor.a = Mathf.PingPong(Time.time, duration) / duration;
//this.GetComponent<SpriteRenderer>().material.color = textureColor;
while (true) { // this could also be a condition indicating "alive or dead"
// we scale all axis, so they will have the same value,
// so we can work with a float instead of comparing vectors
textureColor.a=Mathf.PingPong (Time.time, duration) / duration;
this.transform.transform.GetComponent<Image> ().material.color = textureColor;
// reset the timer
yield return new WaitForSeconds (waitTime);
}
//end of if(this.transform.childCount =0)
}
void stop_Transparency ()
{
this.StopCoroutine (this.co2);
}
}
【问题讨论】:
-
请提供您的代码,如果可能还有图片
-
不清楚。请使用正确的命名约定。您可能是指函数而不是 command?什么是画布位置?你的意思是屏幕空间 - 覆盖? '里面的所有东西都变得透明'这不是你想要达到的吗? Unity 中的透明度?
-
@EmreE 哦,对不起
-
@MrDos 是的兄弟
-
您将此脚本附加到何处?在画布本身或画布的子对象上?
标签: unity3d