【发布时间】:2016-09-10 12:53:12
【问题描述】:
这个错误正在我的脑海中,我无法弄清楚!
我有一把空枪,当我将它移动到弹匣附近时,它有一个碰撞扳机,可以抓住弹匣,按比例缩放并将其插入枪中。这一点工作正常。但是在代码中,我还将杂志父级设置为枪,并将重力设置为 false 并将 isKinematic 设置为 true - 这些位不会发生。因此,弹匣缩放到枪,然后漂浮到远处,当我在 Unity 中查看时,它并没有设置为枪的孩子,并且重力和运动学都未检查,即使我在下面明确设置了这些。如何正确缩放和定位杂志,但没有进行父级和刚体编辑?
代码如下:
//THIS CLASS IS A CHILD OF THE GUN
public class GunBody : MonoBehaviour {
void OnTriggerEnter(Collider collider)
{
Debug.LogError("collision with well");
//check if the collision was with the magazine
if (collider.gameObject.name == "Magazine 1")
{
//reload the gun if it was
addClip(collider.gameObject);
}
}
public void addClip(GameObject magazine)
{
magazine.transform.parent = transform.parent; //DOES NOT WORK
magazine.transform.position = transform.parent.position;
magazine.transform.rotation = transform.parent.rotation;
magazine.transform.localRotation = Quaternion.Euler(-89.96101f, 0f, 0f);
magazine.transform.localScale = new Vector3(14f, 20f, 20f);
magazine.transform.localPosition = new Vector3(0f, -0.8215461f, 1.64772f);
magazine.GetComponent<Rigidbody>().useGravity = false; //DOES NOT WORK
magazine.GetComponent<Rigidbody>().isKinematic = true; //DOES NOT WORK
}
希望有人能发现问题所在?
谢谢
【问题讨论】:
标签: unity3d 3d game-physics