我正在开发一个简单的射击游戏,因为我是 unity 和 C# 的新手,我已经做到了,所以当按下 R 时,它会掉落枪的弹匣并用新的弹匣取而代之。但我有一个 FPS 播放器,枪连接在相机上,当它重新装弹时,弹匣不在需要的地方:
private Rigidbody rb;
public float ammo = 10;
public float maxammo = 20;
public GameObject proj;
public GameObject mag;
public Transform barrel;
public GameObject altmag;
public GameObject spawn;
Vector3 destination;
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
OnFire();
if(Input.GetKeyDown(KeyCode.R)) {
rb = mag.AddComponent<Rigidbody>();
ammo = maxammo;
GameObject newObject = Instantiate(altmag);
newObject.transform.SetParent(gameObject.transform);
newObject.transform.position = spawn.transform.position;
mag = newObject;
}
}
除了重新加载外,其他一切正常。它仍然会更改值,但杂志只是在随机位置生成
我希望它能准确对齐它需要的位置