Help Object spawn Photon

Options
Hello, I wanted a little help with my script because I'm having problems trying to go to the photon I add PhotonNetworking.Instantiate , there are several errors I do not know what to do, thank you, who can help me.

using UnityEngine; using System.Collections; public class WeaponTake : Photon.MonoBehaviour { //public Transform WeaponOn; public int WeaponIdex; public int Price; public Transform Spawnpoint; public Rigidbody Prefab; void OnTriggerEnter(Collider collider) { if(collider.gameObject.tag == "Player") { transform.position = new Vector3(transform.position.x, transform.position.y + 1, transform.position.z); } } void OnTriggerStay(Collider collider){ collider.gameObject.GetComponent<GUISystem> ().Cost = Price; collider.gameObject.GetComponent<GUISystem> ().CostShow = true; if (Input.GetKey(KeyCode.Return) && collider.gameObject.GetComponent<GUISystem> ().Money > Price){ var oldWeapIndex = collider.gameObject.GetComponent<Weapons> ().weaponIndex; collider.gameObject.GetComponent<GUISystem> ().Money -= Price; Rigidbody RigidPrefab; RigidPrefab = Instantiate(Prefab, Spawnpoint.position,Spawnpoint.rotation)as Rigidbody; RigidPrefab.GetComponent<PhotonView> ().RPC ("Prefab", PhotonTargets.AllBuffered, 9); collider.gameObject.GetComponent<GUISystem> ().CostShow = false; Destroy(gameObject); } } void OnTriggerExit(Collider collider) { collider.gameObject.GetComponent<GUISystem> ().CostShow = false; transform.position = new Vector3(transform.position.x, transform.position.y -1, transform.position.z); } }

Comments

  • Hi Erisangt,

    you are calling Instantiate function, which will only create an object on your local machine. This object won't neither be created on remote clients nor synchronized across the network. If you want to spawn an object on the network you have to use PhotonNetwork.Instantiate(...). Therefore I would strongly recommend you reading and working through the PUN Basics Tutorial. There is also a chapter (part 8) about Instantiation.