Unity3d 使用中的问题统一中的协同程序
嗨,亲爱的朋友们 我写了一个游戏对象的透明跟随类,并将其作为一个组件添加到几个游戏对象中,但当我按下play按钮时,这个类作为一个组件出现的所有对象都开始打开和关闭。。。如果我只想打开一个叫名字的游戏对象……打开和关闭。请帮助我 请Unity3d 使用中的问题统一中的协同程序,unity3d,Unity3d,嗨,亲爱的朋友们 我写了一个游戏对象的透明跟随类,并将其作为一个组件添加到几个游戏对象中,但当我按下play按钮时,这个类作为一个组件出现的所有对象都开始打开和关闭。。。如果我只想打开一个叫名字的游戏对象……打开和关闭。请帮助我 请 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Threading;
public class Transparent : MonoBehaviour {
private float duration = .7f;
public float waitTime;
IEnumerator co;
// Update is called once per frame void
public void Start()
{
this.co=this.blink();
this.StartCoroutine (this.co);
}
IEnumerator blink() {
Color textureColor = this.GetComponent<SpriteRenderer> ().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.GetComponent<SpriteRenderer> ().material.color = textureColor;
// reset the timer
yield return new WaitForSeconds (waitTime);
}
//end of if(this.transform.childCount =0)
}
void stop_Transparency ()
{
this.StopCoroutine (co);
}
}
and write different class for transparency dice that has child follow class
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class dice_Transparent : MonoBehaviour {
private float duration = .7f;
public float waitTime;
IEnumerator co;
// Update is called once per frame void
public void Start()
{
this.co=this.dice_blink();
this.StartCoroutine (this.co);
}
IEnumerator dice_blink() {
Color textureColor0 = this.transform.GetChild (0).GetComponent<SpriteRenderer> ().material.color;
Color textureColor1 = this.transform.GetChild (1).GetComponent<SpriteRenderer> ().material.color;
Color textureColor2 = this.transform.GetChild (2).GetComponent<SpriteRenderer> ().material.color;
Color textureColor3 = this.transform.GetChild (3).GetComponent<SpriteRenderer> ().material.color;
Color textureColor4 = this.transform.GetChild (4).GetComponent<SpriteRenderer> ().material.color;
Color textureColor5 = this.transform.GetChild (5).GetComponent<SpriteRenderer> ().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
textureColor0.a=Mathf.PingPong (Time.time, duration) / duration;
textureColor1.a=Mathf.PingPong (Time.time, duration) / duration;
textureColor2.a=Mathf.PingPong (Time.time, duration) / duration;
textureColor3.a=Mathf.PingPong (Time.time, duration) / duration;
textureColor4.a=Mathf.PingPong (Time.time, duration) / duration;
textureColor5.a=Mathf.PingPong (Time.time, duration) / duration;
this.transform.GetChild (0).GetComponent<SpriteRenderer> ().material.color = textureColor0;
this.transform.GetChild (1).GetComponent<SpriteRenderer> ().material.color = textureColor1;
this.transform.GetChild (2).GetComponent<SpriteRenderer> ().material.color = textureColor2;
this.transform.GetChild (3).GetComponent<SpriteRenderer> ().material.color = textureColor3;
this.transform.GetChild (4).GetComponent<SpriteRenderer> ().material.color = textureColor4;
this.transform.GetChild (5).GetComponent<SpriteRenderer> ().material.color = textureColor5;
// reset the timer
yield return new WaitForSeconds (waitTime);
}
//end of if(this.transform.childCount =0)
}
void stop_Transparency ()
{
this.StopCoroutine (this.co);
}
}
请帮助我…pleaseStart()是单行为保留函数,在启用脚本时默认执行该函数。您可以在此处阅读有关启动函数的信息:
如果要手动调用函数,请使用其他函数名。
例如,将start函数的内容复制到名为MyStart()的函数中,然后调用该函数。像这样:
test.gameObject.GetComponent<Transparent>().MyStart();
test.gameObject.GetComponent().MyStart();
@alikarimifard,我认为您面临的问题是所有协同程序都在一起启动,但您只希望启动特定的协同程序。从你的描述中我再也看不懂了。我根据它提供了解决方案。我不明白,如果你只是说,“那是行不通的。”请更具体地说明这个问题。
test.gameObject.GetComponent<Transparent>().MyStart();