我成功地淡化/消除了团结的效果。
但我不能阻止这种影响。
我的游戏对象的透明度:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Transparent_Of_Sprite : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//----------------------------------------------------
private float duration = .7f;
public float waitTime;
IEnumerator co2;
Color textureColor;
// 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;
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)
}
public void stop_Transparency ()
{
textureColor.a = 5;
this.GetComponent<SpriteRenderer> ().material.color = textureColor;
this.StopCoroutine (this.co2);
}
}
// ------------------------- 我的停止透明度代码是------------------------ //
Game_Controller.Database [1, 1].Nute_M.GetComponent<Transparent_Of_Sprite> ().stop_Transparency ();
请不要为我工作。请帮助
答案 0 :(得分:1)
替换它:
this.co2=this.blink();
this.StartCoroutine (this.co2);
用这个:
co2 = StartCoroutine(Blink());
你正在以正常方法开始协程。
编辑:
同时将IEnumerator co2;
替换为Coroutine co2;