- Home /
Problem with my weapon change system
Hello everybody, I am trying to create a solid weapon change system for my multiplayer FPS but i am stuck to a problem while deleting my old weapon prefab so i can instatiate my new one ( without having 2 weapons at the same time ).. So here is my script where i instatiate or destroy the weapons ..
public void ChangeWeapon(Weapon newWeapon)
{
if (GetComponent<PhotonView> ().isMine) {
if (currentWeaponGO != null) {
GetComponent<PhotonView> ().RPC ("DestroyWeapon_RPC", PhotonTargets.All, viewID);
}
GetComponent<PhotonView> ().RPC ("ChangeWeapon_RPC", PhotonTargets.All, newWeapon.name);
currentWeaponGO = PhotonView.Find (viewID).gameObject;
}
}
[RPC] public void DestroyWeapon_RPC (int weaponID){
GameObject weapon=PhotonView.Find(weaponID).gameObject;
Destroy (weapon);
}
[RPC] public void ChangeWeapon_RPC (string newWeapon){
GameObject newWeap = (GameObject)Resources.Load(newWeapon) ;
GameObject weaponGo;
weaponGo = (GameObject)Instantiate(newWeap,weaponPos.position, weaponPos.rotation);
weaponGo.transform.parent = weaponPos.transform;
viewID = weaponGo.GetComponentInChildren<PhotonView> ().viewID;
}
the problem is that i instatiate the object and its viewID = 0 because the server owns it.. Conclusion: when destroying a weapon every player loses his armed weapon what pretty sure nobody wants to.. i tried other ways with Photon.Instatiate.. but this has several other problems.. Has anybody an idea what I can do so everything works smooth?? greets and thank you!
Your answer
![](https://koobas.hobune.stream/wayback/20220613161046im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Weapon Customizations Script Problem 0 Answers
My imported weapon flips around. 1 Answer
Weapon pick up and switching script 2 Answers
How do i get a weapon to follow the first person controller up and down? 0 Answers