ฉันไม่เข้าใจว่าทำไม
ฉันได้อ่านเอกสารเกี่ยวกับเรื่องนี้มากมายแล้วและมีความคิดเห็นมากมาย
StopCoroutine (สตริง) สามารถหยุด coroutine ที่เริ่มต้นด้วย StartCoroutine (สตริง) เท่านั้น
รหัสอยู่ด้านล่าง
ในคลาส CharTouchControl.cpp
if( Input.GetKeyDown( KeyCode.Q ) )
{
_CharControl.StartCoroutine("useFever", 10);
}
_CharControl เป็นสมาชิกของ CharTouchControl และแน่นอนว่า _CharControl อ้างอิงอินสแตนซ์ CharControl ด้านล่าง
และ CharControl ในคลาส
public IEnumerator useFever(float _duration = 10)
{
if( m_nUseFever < _nFeverMax )
{
Debug.Log("Stop!!");
StopCoroutine("useFever");
yield return new WaitForEndOfFrame();
}
m_fgCharState = CharState._FEVER;
// fever particle
m_psFeverPaticle.Simulate(4);
yield return new WaitForEndOfFrame();
} // end of useFever
เมื่อ m_nUseFever ‹ _nFeverMax เป็นจริง ฉันจะเห็น "หยุด!!" บันทึก,
แต่โครูทีนไม่หยุดและจำลองปาติเคิล
มีใครช่วยเรื่องนี้บ้างไหม?
StopCoroutine
จากภายในโครูทีน? ใช้yield break
ในคำสั่งif
แรกแทน - person Jerdak   schedule 13.11.2013StopCoroutine
ซึ่งจะป้องกันไม่ให้ส่วนที่เหลือของฟังก์ชัน (ซึ่งรวมถึงการจำลองอนุภาค) ดำเนินการ คุณกำลังพยายามบรรลุผลคืออะไร? - person Dan Puzey   schedule 13.11.2013