How would i have it so that both of the players in my game can see moving objects, because i have it so the players can see each other fine and when the move on one instance of the game the other player can see it, but how would i have this done with game objects. I have it so that the players can pick up objects but when a player picks up an object on one screen/game the other player does not see this on there game. Here is some of my code:
using UnityEngine;
using System.Collections;
public class NetworkCharacter : Photon.MonoBehaviour {
Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;
void Update(){
if (photonView.isMine) {
}
else {
transform.position = Vector3.Lerp (transform.position, this.realPosition, 0.1f);
transform.rotation = Quaternion.Lerp (transform.rotation, this.realRotation, 0.1f);
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if (stream.isWriting) {
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else {
this.realPosition = (Vector3) stream.ReceiveNext();
this.realRotation = (Quaternion) stream.ReceiveNext();
}
}
}
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
public GameObject standByCamera;
void Start () {
PhotonNetwork.ConnectUsingSettings ("0.0.1");
}
void OnGUI () {
UnityEngine.GUILayout.Label ( PhotonNetwork.connectionStateDetailed.ToString() );
}
void OnJoinedLobby () {
PhotonNetwork.JoinRandomRoom ();
}
void OnPhotonRandomJoinFailed () {
PhotonNetwork.CreateRoom ( "MAIN" );
}
void OnJoinedRoom () {
GameObject myPlayerGO = PhotonNetwork.Instantiate ("PlayerController", Vector3.zero, Quaternion.identity, 0);
GameObject _minimap = PhotonNetwork.Instantiate ("MinimapCamera", new Vector3(0, 100, 0), Quaternion.Euler(90 ,0 ,0), 0);
GameObject box = PhotonNetwork.Instantiate ("FlatCube", new Vector3(5, 1, 5), Quaternion.identity, 0);
standByCamera.SetActive (false);
myPlayerGO.transform.FindChild ("Main Camera").gameObject.SetActive(true);
myPlayerGO.transform.FindChild ("MinimapCamera").gameObject.SetActive(true);
((MonoBehaviour)myPlayerGO.GetComponent ("FirstPersonController")).enabled = true;
((MonoBehaviour)box.GetComponent ("Pickupable")).enabled = true;
}
}
I have the Network character for my player characters so they can see each other
I have the Network manager to setup the games