前提・実現したいこと
Unityで3Dのゲームを制作しているのですが別のscriptのコルーチンの処理を止めて処理を行う前の状態にしたいです
正しいやり方や何か良い方法があれば教えていただきたいです。
発生している問題・エラーメッセージ
該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; public class InterruptionButtonScr : MonoBehaviour { GameObject Coniferous; GameObject ActionButton; // Use this for initialization void Start() { Coniferous = GameObject.Find("Coniferous"); ActionButton = GameObject.Find("ActionButton"); } // Update is called once per frame void Update() { } public void OnClick() { ActionButton di = GetComponent<ActionButton>(); StopCoroutine("ExecutionTime"); } }
スタートコルーチンが書かれているscript
using UnityEngine; using System.Collections; using UnityEngine.UI; public class ActionButton : MonoBehaviour { public float _mb; public GameObject NotFixed; public GameObject DestroyButton; public GameObject GatheringButton; public GameObject StopProcessingButton; public GameObject Coniferous; public GameObject Branches; public float intarvar = 10.0f; Slider _slider; //中断するかどうかのフラグ public bool Interruption; //2倍減少中かのフラグ private bool boost = false; //標準の減少量 private float decreaseSpeed = 0.1f; void Start() { // スライダーを取得する _slider = GameObject.Find("CalorieSlider").GetComponent<Slider>(); StopProcessingButton.SetActive(false); } void Update() { if(boost) { _slider.value -= Time.deltaTime * decreaseSpeed * 10000.0f; } else { _slider.value -= Time.deltaTime * decreaseSpeed; } } public void OnClick() { //Coniferous = GameObject.Find("Coniferous"); //Renderer ConiferousRenderer = Coniferous.GetComponent<Renderer>(); //Destroy(Coniferous); StartCoroutine("ExecutionTime"); //ConiferousRenderer.enabled = false; //Instantiate(Branches, transform.position, Quaternion.identity); //DestroyButton.SetActive(false); //GatheringButton.SetActive(false); } IEnumerator ExecutionTime() { DestroyButton.SetActive(false); GatheringButton.SetActive(false); StopProcessingButton.SetActive(true); boost = true; yield return new WaitForSeconds(5.0f); boost = false; StopProcessingButton.SetActive(false); //Debug.Log("ok"); //GameObject.Find("DestroyButton").GetComponent<Image>().enabled = false; gameObject.SetActive(false); } }
試したこと
ボタンが押されたときにActionButtonスクリプトのコルーチンをStopCoroutine()で止まるはずが止まらず
補足情報(FW/ツールのバージョンなど)
Unity 2018.1.0f2
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/14 02:17
2018/06/14 06:12
2018/06/16 09:20
2018/06/17 15:42
2018/06/18 01:24
2018/06/20 10:05