【发布时间】:2022-01-11 10:52:27
【问题描述】:
是否可以跳过列表中的活动对象。
我正在制作保龄球虚拟现实游戏。保龄球第二次进入触发区域时,会激活一个检查棋子的 foreach 代码已经下降。在你投下第二个保龄球之前工作得很好。然后我得到了找不到活动棋子的错误。他有可能跳过那些吗?
public void PawnHasFallen()
{
Debug.Log("Calling this script");
//see of the pawn has moved after the wait in the other script
if (!Mathf.Approximately(Vector3.Angle(Vector3.up, transform.up), 0f))
{
StartCoroutine(PawmEnumerator());
Debug.Log(pawnName.name + " has fallen", this);
//function
}
else
{
Debug.Log(pawnName.name + " is still standing", this);
//fuint
}
}
IEnumerator PawmEnumerator()
{
if (pawnName.activeInHierarchy == true)
{
rb.velocity = Vector3.up * trustFroce * Time.deltaTime;
yield return new WaitForSeconds(2);
rb.constraints = RigidbodyConstraints.FreezeAll;
Boom();
yield return new WaitForSeconds(0.5f);
pawnName.gameObject.SetActive(false);
}
}
public void Boom()
{
foreach (var ps in psPawn)
{
ps.Play();
}
}
public IEnumerator OnTriggerEnter(Collider collision)
{
Debug.Log("Big balls");
//if the ball hits the end of the bowling ally start this
if (collision.gameObject.tag == "Ball")
{
Debug.Log("Start de second wait");
//wait 5 second for starting the fuction
yield return new WaitForSeconds(5);
Debug.Log("Ended the waiting");
//this function sees if the pawn has fallen and then gives you points
//pawn.PawnHasFallen();
foreach(var pawn in pawns)
{
pawn.PawnHasFallen();
}
}
}
【问题讨论】:
标签: unity3d foreach virtual-reality