如何使 StartCoroutine 统一工作?



我是 c# 的新手,我试图让一个平台在玩家站在上面时倒塌。我使用了 StartCoroutine,所以平台在五秒钟后就崩溃了,但由于某种原因,我的 couroutine 不起作用。

这是代码:

public GameObject player;


private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
rb.useGravity = false;
//rb.isKinematic = false;
}
// Update is called once per frame
void Update()
{
}

private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "player")
{
StartCoroutine(ObjectFall());
}
}
IEnumerator ObjectFall()
{
yield return new WaitForSeconds(5f);
Debug.Log("Its working");

this.rb.useGravity = true;
//this.rb.isKinematic = true;
}

}

如果您没有函数的参数,则不需要使用 IEnumerable。你可以使用 Invoke("ObjectFall", 5( 并将你的 IEnumerable 变为 void 而没有收益。它可能不是问题的根源,但请尝试一下。游戏中的规模可能是错误的,这就是质量 1000 起作用的原因。尝试固定整个场景的比例。记住 1 个单位 = 1 米或多或少

最新更新