停止协程不要团结一致 [英] stop coroutine don't work in unity

查看:119
本文介绍了停止协程不要团结一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功地淡入淡出了效果.

I succeeded to fade in/fade out effect in unity.

但是我不会停止这种影响.

But i don't stop this effect.

我的游戏对象的类透明度:

my class transparency of a game object :

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);

    }
}

//------------------------- 我的停止透明度代码是------------------------//

//------------------------- my code for stop transparency is ------------------------//

Game_Controller.Database [1, 1].Nute_M.GetComponent<Transparent_Of_Sprite> ().stop_Transparency ();

不为我工作.请帮助

推荐答案

替换此:

this.co2=this.blink();
this.StartCoroutine (this.co2);

与此:

co2 = StartCoroutine(Blink());

您像正常方法一样启动协程.

You were starting the coroutine like a normal method.

也将IEnumerator co2;替换为Coroutine co2;

这篇关于停止协程不要团结一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆