So, I’m writing my first multiplayer application for learning experiences and I’m following a very in-depth tutorial, I also have background in java programming although nothing when it comes to networking… anyhow what’s occuring here is the following.
Only the first connection has access over
if(networkView.isMine) {
After that, Disconnection, or additional connection, the view is not owned by the user, from what I was reading each client was supposed to have it’s own unuique view, anyhow I was trying to write a script that was attatched to the player to send the position to the server, anyone want to help me get this working?
using UnityEngine;
using System.Collections;
public class MovementUpdate : MonoBehaviour {
//Variables Start___________________________________
private Vector3 lastPosition;
private Quaternion lastRotation;
private Transform myTransform;
//Variables End_____________________________________
// Use this for initialization
void Start ()
{
if(networkView.isMine == true)
{
myTransform = transform;
networkView.RPC("updateMovement", RPCMode.OthersBuffered,
myTransform.position, myTransform.rotation);
}
else
{
Debug.Log("Disabling update");
enabled = false;
}
}
// Update is called once per frame
void Update ()
{
if(Vector3.Distance(myTransform.position, lastPosition) >= 0.1)
{
lastPosition = myTransform.position;
networkView.RPC("updateMovement", RPCMode.OthersBuffered,
myTransform.position, myTransform.rotation);
}
if(Quaternion.Angle(myTransform.rotation, lastRotation) >= 1)
{
lastRotation = myTransform.rotation;
networkView.RPC("updateMovement", RPCMode.OthersBuffered,
myTransform.position, myTransform.rotation);
}
}
[RPC]
void updateMovement (Vector3 newPosition, Quaternion newRotation)
{
transform.position = newPosition;
transform.rotation = newRotation;
}
}
Also, I know
if(networkView.isMine) {
would work instead of adding the == true but I did it anyhow, shrug
EDIT: On the video tutorial I’m watching he uses unity 3.6, although the code does work, he even allows us to download is script and this one is actually his version (Mine did the checks differently) and still the same issue