StartCoroutine(MakeNextBall(hand,0.01f));
StartCoroutine(DestryPreviousBall(Basketball,3.0f));
IEnumerator MakeNextBall(Transform pos,float time)//多线程返回参数IEnumerator
{
yield return new WaitForSeconds(time);
Basketball = Instantiate(TempBasketBall,hand.position,hand.rotation) as Rigidbody;
}
IEnumerator DestryPreviousBall(Rigidbody ball,float time)
{
yield return new WaitForSeconds(time);
if(ball)
{
Destroy(ball.gameObject);
}
}
本文介绍了如何使用Unity的协程控制篮球游戏中的球体生成与销毁过程。通过两个协程函数MakeNextBall和DestryPreviousBall实现球体定时生成及旧球体的销毁。MakeNextBall函数在指定时间后生成新的篮球实例,而DestryPreviousBall则负责延迟一段时间后销毁当前存在的篮球。
10万+

被折叠的 条评论
为什么被折叠?



