这是玛莎 我正在创建一个名为(Bridge Race)的安卓游戏 我想用我的播放器(胶囊)拿起盒子并将它们堆叠在一起,用对撞机 所以我的问题是如何将它们保存到变量并将碰撞器的位置更改为播放器的背面以便我可以随身携带盒子,有人可以帮我吗?
我试过了
private void OnTriggerEnter(Collider other)
{
if(other.tag == "RedCube")
{
Transform otherTransform = other.transform.parent;
Rigidbody otherRigidbody = other.GetComponent<Rigidbody>();
otherRigidbody.isKinematic = true;
other.enabled = false;
if (parentPickup == null )
{
parentPickup = otherTransform;
parentPickup.position = stackPosition.position;
parentPickup.parent = stackPosition;
}
else
{
parentPickup.position += Vector3.up * (otherTransform.localScale.y);
otherTransform.position = stackPosition.position;
otherTransform.parent = stackPosition;
}
}
}