Question by
macthelost · Jun 30, 2016 at 04:48 PM ·
networkingmultiplayerhowpuninternet
[PUN] All players control one object
I'm just trying to make a simple multiplayer fps, here are my network scripts: Network Manager
using Photon;
using UnityEngine;
using System.Collections;
public class NetworkManager : Photon.PunBehaviour {
// Use this for initialization
void Start () {
PhotonNetwork.ConnectUsingSettings ("0.1");
PhotonNetwork.logLevel = PhotonLogLevel.Full;
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
}
void OnJoinedLobby () {
PhotonNetwork.JoinRandomRoom ();
}
void OnPhotonRandomJoinFailed() {
Debug.Log ("NO AVAILABLE ROOMS");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom () {
GameObject Player = PhotonNetwork.Instantiate ("Player", Vector3.zero, Quaternion.identity, 0);
GameObject physCube = PhotonNetwork.Instantiate ("Cube", Vector3.zero, Quaternion.identity, 0);
CharacterController controller = Player.GetComponent<CharacterController> ();
controller.enabled = true;
}
}
Network Player
using UnityEngine;
using Photon;
public class NetworkCharacter : Photon.MonoBehaviour
{
private Vector3 correctPlayerPos;
private Quaternion correctPlayerRot;
// Update is called once per frame
void Update()
{
if (!photonView.isMine)
{
transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
// We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
// Network player, receive data
this.correctPlayerPos = (Vector3)stream.ReceiveNext();
this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
}
Here's my Photon View: Photon View
Comment