我在使用一個簡單的 hingejoint2d 時遇到了麻煩,它由一個簡單的鏈條組成,上面附有一個盒子。它工作正常,直到游戲重新啟動,當游戲重新啟動時,盒子從鏈條上掉下來,但鏈條繼續在原處。我不知道是什么原因造成的。這是重置對象的代碼。 private Quaternion startRot; private Vector3 startLocalScale; private Rigidbody2D rb; private HingeJoint2D hj; // Start is called before the first frame update void Start() { startPos = transform.position; startRot = transform.rotation; startLocalScale = transform.localScale; hj = GetComponent<HingeJoint2D>(); if (GetComponent<Rigidbody2D>() != null) { rb = GetComponent<Rigidbody2D>(); } } // Update is called once per frame void Update() { } public void ResetObjects() { transform.position = startPos; transform.rotation = startRot; transform.localScale = startLocalScale; if (hj != null) return; if (rb != null) { rb.velocity = Vector3.zero; } }```
游戲重置時,Hinge Joint 2D 停止正常工作
慕碼人2483693
2023-04-29 16:34:21