static IEnumerator StartWaitOneSecondLog() { ReturnCoroutine <string> bc = new ReturnCoroutine <string>(WaitOneSecondLog()); yield return(bc.coroutine); string result = bc.result; Debug.Log(result); }
static IEnumerator StartShotRingToCenter(GameObject bulletPrefab, Vector3 position, Quaternion rotation, int bulletsNumber, float radius, float effectTime) { ReturnCoroutine <GameObject[]> returnCoroutine = new ReturnCoroutine <GameObject[]>(ShotAndReturnRingToCenter(bulletPrefab, position, rotation, bulletsNumber, radius, effectTime)); yield return(new WaitForSeconds(effectTime)); if (returnCoroutine.result == null) { yield return(null); } foreach (GameObject bullet in returnCoroutine.result) { bullet.SetActive(true); } }
static IEnumerator StartShotFanShaped(GameObject bulletPrefab, Vector3 position, Quaternion rotation, int bulletsNumber, float angle, float effectTime) { ReturnCoroutine <GameObject[]> returnCoroutine = new ReturnCoroutine <GameObject[]>(ShotAndReturnFanShapedBullets(bulletPrefab, position, rotation, bulletsNumber, angle, effectTime)); yield return(new WaitForSeconds(effectTime)); if (returnCoroutine.result == null) //如果游戏在生成的最后一帧卡住了,有可能导致子弹生成被卡在最后一次生成但激活的倒计时已经结束了,这时就发生了空引用,在检测到返回值还没返回时等一帧让生成过程完成 { yield return(null); } foreach (GameObject bullet in returnCoroutine.result) { bullet.SetActive(true); } }
static IEnumerator StartShotTransverselyLine(GameObject bulletPrefab, Vector3 position, Quaternion rotation, int bulletsNumber, float angle, float effectTime) { ReturnCoroutine <GameObject[]> returnCoroutine = new ReturnCoroutine <GameObject[]>(ShotAndReturnTransverselyLineBullets(bulletPrefab, position, rotation, bulletsNumber, angle, effectTime)); yield return(new WaitForSeconds(effectTime)); if (returnCoroutine.result == null) { yield return(null); } foreach (GameObject bullet in returnCoroutine.result) { bullet.SetActive(true); } }