我在使用一个简单的 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;
}
}```
Qyouu
相关分类