IEnumerator StartRightLiziCard()//在下面函数的调用开始执行 { yield return new WaitForSeconds(1.0f);//等待1秒针 areas[Index].energyGun.SetActive(true);//执行 } int Index = 1; public void playEnergyGun(int seatIndex, bool isPlay)//开始执行 { if (isPlay) { if (areas[seatIndex - 1].isEnergyOver) { areas[seatIndex - 1].isEnergyOver = false; Index = seatIndex - 1; StartCoroutine("StartRightLiziCard");此处执行到上面函数的接口。。。但是同时向下面代码执行。。 int spriteName = Convert.ToInt32(areas[seatIndex - 1].gunBarrel.GetComponent<UISprite>().spriteName); areas[seatIndex - 1].gunBarrel.GetComponent<UISprite>().spriteName = (spriteName + 4).ToString(); areas[seatIndex - 1].particle.Play(); } } else { if (!areas[seatIndex - 1].isEnergyOver) { areas[seatIndex - 1].isEnergyOver = true; areas[seatIndex - 1].energyGun.SetActive(false); int spriteName = Convert.ToInt32(areas[seatIndex - 1].gunBarrel.GetComponent<UISprite>().spriteName); areas[seatIndex - 1].gunBarrel.GetComponent<UISprite>().spriteName = (spriteName - 4).ToString(); areas[seatIndex - 1].particle.Play(); } } }
注意:相当于开启了一个子线程,但是主线程仍向下执行。
时间: 2024-11-07 23:38:09