我这里有几个问题。
当客户按下'e'时,会显示“正在加载武器”,并且该武器对象同时出现在客户和主机上,但是在客户端,武器很小(没有缩放比例)已经失去了父级关联,不受预期的控制。 (当主机看到预期的武器时)
“ Cmd_PickUpWeapon调用”也不会打印,尽管该函数似乎已经被调用了? (产生了武器)
这是我的代码:
if (Input.GetKeyDown("e")) { // add short timer to hold 'e'?
print("loading weaponing")
Cmd_LoadWeapon("pistol");
}
[Command]
private void Cmd_PickUpWeapon(string weaponToLoad) {
print("Cmd_PickUpWeapon called");
GameObject weaponPrefab = Resources.Load("Prefabs/Weapons/"+ weaponToLoad) as GameObject;
weapon = Instantiate(weaponPrefab, this.transform.position, Quaternion.identity) as GameObject;
weaponEquipt = weaponToLoad;
weapon.gameObject.name = weaponEquipt;
weapon.transform.SetParent(this.transform);
weapon.transform.localPosition = weaponPrefab.transform.localPosition;
weapon.transform.localScale = new Vector3(1f, 1f, 1f);
NetworkServer.SpawnWithClientAuthority(weapon, connectionToClient);
}