Unity3d unity 3d中的稀疏性
我希望我的问题不会重复; 我的团结有问题。 我为对象的透明度(淡入淡出循环)编写了一个类。这是正确的。 我在场景中放了两个按钮,它们在画布上。 运行之后,尽管我已经为画布中的一个对象编写了一个透明命令,但其中的所有内容都将转到透明(淡入淡出循环)。 我不知道。 请帮忙 我的班级Unity3d unity 3d中的稀疏性,unity3d,Unity3d,我希望我的问题不会重复; 我的团结有问题。 我为对象的透明度(淡入淡出循环)编写了一个类。这是正确的。 我在场景中放了两个按钮,它们在画布上。 运行之后,尽管我已经为画布中的一个对象编写了一个透明命令,但其中的所有内容都将转到透明(淡入淡出循环)。 我不知道。 请帮忙 我的班级 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Sys
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);
}
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine.UI;
使用系统线程;
使用制度;
公共类透明:单一行为{
私人浮动持续时间=.7f;
公共浮动等待时间;
二氧化碳计量器;
//每帧调用一次更新
公共无效启动和传输()
{
this.co2=this.blink();
this.start例程(this.co2);
}
IEnumerator blink(){
//颜色纹理颜色=this.transform.GetComponent().material.Color;
颜色纹理颜色=this.transform.GetComponent().material.Color;
//textureColor.a=乒乓球(Time.Time,duration)/持续时间;
//this.GetComponent().material.color=textureColor;
while(true){//这也可能是表示“活着或死了”的条件
//我们缩放所有轴,使它们具有相同的值,
//所以我们可以用浮点来代替比较向量
textureColor.a=乒乓球(Time.Time,duration)/持续时间;
this.transform.transform.GetComponent().material.color=textureColor;
//重置计时器
返回新的WaitForSeconds(waitTime);
}
//if结束(this.transform.childCount=0)
}
无效停止_透明度()
{
this.StopCoroutine(this.co2);
}
}
好的,我发现你的问题主要是
this.transform.transform.GetComponent();
由于双重变换,它到达父级的一个更高级别,即画布本身。所以画布中的所有内容都会失去alpha值
还对代码进行了一些编辑。不使用材质颜色,而是直接更改图像组件的alpha颜色值
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine.UI;
使用系统线程;
使用制度;
公共类透明:单一行为
{
私人浮动持续时间=.7f;
公共浮动等待时间;
二氧化碳计量器;
公共无效启动和传输()
{
this.co2=this.blink();
this.start例程(this.co2);
}
IEnumerator blink()
{
//颜色纹理颜色=this.transform.GetComponent().material.Color;
颜色纹理颜色=this.transform.GetComponent().Color;
//textureColor.a=乒乓球(Time.Time,duration)/持续时间;
//this.GetComponent().material.color=textureColor;
while(true)
{//这也可能是一种表示“活着或死了”的情况
//我们缩放所有轴,使它们具有相同的值,
//所以我们可以用浮点来代替比较向量
textureColor.a=乒乓球(Time.Time,duration)/持续时间;
this.transform.GetComponent().color=textureColor;
//重置计时器
返回新的WaitForSeconds(waitTime);
}
//if结束(this.transform.childCount=0)
}
无效停止_透明度()
{
this.stopcroutine(this.co2);
}
}
我已将此脚本附加到画布中的一个按钮。还可以在同一按钮的On Click()
中运行start\u transparecncy()
函数
按下按钮后,只有按钮的alpha值发生变化
如果您愿意,您可以在单击()时更改
,并添加另一个按钮。请提供您的代码,如果可能,图像也不清楚。请使用正确的命名约定。你可能是指功能而不是命令?什么是帆布场所?你是说屏幕空间-覆盖里面所有的东西都是透明的,这不是你想要达到的吗?团结透明?@EmreE哦,我是sorry@MrDos是的,兄弟,你把这个脚本附在哪里了?在画布本身或画布的子对象上?我的朋友,我需要在开始场景中运行淡入/淡出…我使用脚本运行开始透明度方法…。例如:throw_text_p1.gameObject.GetComponent().start_transparecncy();指挥部。