- Home /
Unity Photon syncing objects
I am using Photon Networking to add multiplayer functionality to my game. It's going great so far, the only thing left to do is synching objects across the network so that other players can see and interact with spawned object prefabs. Simply adding a Photonview script to the prefabs and observing the transform hasn't worked. Here is the first spawn script:
#pragma strict
var WoodCube:Transform;
private var Timer:float;
function Awake() {
Timer = Time.time + 30;
}
function Update() {
if (Timer < Time.time) {
Instantiate(WoodCube, transform.position, transform.rotation);
Timer = Time.time + 30;
}
}
I realize that with the timer running for different players joining at different times the spawned objects each player is seeing may actually be different. How can I make the spawned game objects be observed by multiple players? For example I have food objects which disappear when the player collides with them and can also be picked up and moved, However when I spawn two players at the same food spawn and one player walks into a food object or moves it after it has spawned the other player does not see any change to the item.
I also have a shoot script which spawns bullets at the barrel of a gun and then shoots it forward when the player clicks on the gun. If I spawn two players both looking at the barrel of the gun and in one instance of the build I click on the gun, I see the bullet fire but the other player does not.
using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
public Rigidbody projectile;
public float speed = 20;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void OnMouseDown() {
audio.Play();
{
Rigidbody instantiatedProjectile = Instantiate(projectile,
transform.position,
transform.rotation)
as Rigidbody;
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
}
}
}
Any help would be extremely appreciated.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Multiplayer Networking 1 Answer
Unet spawn a camera? 0 Answers
Shoot Projectile Where Camera Faces [PLEASE HELP!] 2 Answers
Sequencing Spawning for Multiplayer 1 Answer