- Home /
How to update a script to a network script
Hey, sorry to ask but I'm new at this and while my script works perfectly I've ran into an issue. As such I've made a basic script that creates a prefab object at the ray cast hit location and while it appears to the person whose placed it, I have no idea on how to make it appear for other players in the game. As all they see is when the placer is standing on it they are floating.....anyway I've tried a couple solutions yet I can never get it too work, so if anyone could please tell me how I would go about this, I would be most grateful.
using UnityEngine;
using System.Collections;
public class delete : MonoBehaviour {
RaycastHit hit;
public Transform prefab;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Ray ray = camera.ViewportPointToRay (new Vector3 (0.5F, 0.5F, 0));
Vector3 G = new Vector3 (Mathf.Round (hit.point.x), Mathf.Ceil (hit.point.y), Mathf.Round (hit.point.z));
if (Physics.Raycast (ray, out hit)) {
if (Input.GetMouseButtonDown (2)) {
Destroy (hit.collider.gameObject);
}
if (Input.GetMouseButtonDown (1)) {
Instantiate (prefab, G, Quaternion.identity);
}
if (Input.GetMouseButton (1)) {
animation.Play ("right_hand_build 1");
}
}
}
}
You will need to send an RPC call to the other players getting them to see what you need - if you are just looking for the created object to appear you should use Network.Instantiate
cheers for the reply, however i've tried this before and I ran into an issue about overload, how would I be able to work around this...hahaha sorry
Answer by fholm · Mar 27, 2014 at 09:35 AM
You should use PhotonNetwork.Instantiate
I've tried this and now are met with it stating that I'm not connected to the server however I'm using photon if that affects anything.
cheers, that work hahaha I feel like a fool but thanks