- Home /
Movement update doesn't work
I got 3 scripts to update the movement of a player, 1 script on a server another on the object that has to move (the object spawns on the both clients) and the last in a random scene as a Menu;
The problem is if I start the game with 2 clients the objects don't move for eachother. In one of the scripts you'll see PVPC I checked it if that worked and it does work. So if anyone could help me it would be a great help. Because I'm getting no errors.
I parsed alot out of the file that I've normely, because I only gave the parts that can cause the problem and the conncetion to server and other clients works fine.
Server:
using UnityEngine;
using System.Collections;
using System.IO;
public class ServerPVP : MonoBehaviour
{
//Que1
int PVPQueN;
int PVPP1;
int PVPP2;
NetworkPlayer player1;
NetworkPlayer player2;
void Start()
{
PVPQueN = 0;
PVPP1 = 1;
PVPP2 = 2;
}
void Update()
{
if(PVPQueN < 0)
{
PVPQueN = 0;
}
if(PVPQueN == 2)
{
PVPQueN = 0;
networkView.RPC("StartPVP",player1,player2,PVPP1);
networkView.RPC("StartPVP",player2,player1,PVPP2);
}
[RPC]
void PVPQue(NetworkPlayer Player)
{
if(PVPQueN == 1)
{
player2 = Player;
PVPQueN += 1;
}
if(PVPQueN == 0)
{
player1 = Player;
PVPQueN += 1;
}
}
[RPC]
void StartPVP(NetworkPlayer Player,int PVPp)
{
/*if(PVPp == 1)
{
PVPP = 1;
}
if(PVPp == 2)
{
PVPP = 2;
}*/
//PVPC = Player;
Application.LoadLevel(3);
}
[RPC]
void PVPMove(Vector3 newPosition, Quaternion newRotation, Vector3 newScale, NetworkPlayer PlayerC)
{
networkView.RPC("MoveClone", PlayerC, newPosition, newRotation, newScale);
}
[RPC]
void MoveClone(Vector3 newPosition, Quaternion newRotation, Vector3 newScale)
{
/*myTransform.position = newPosition;
myTransform.rotation = newRotation;
myTransform.localScale = newScale;*/
}
}
Player:
using UnityEngine;
using System.Collections;
public class PVPInterface2 : MonoBehaviour
{
private Vector3 lastPosition;
private Quaternion lastRotation;
private Transform myTransform;
private NetworkPlayer PVPC;
void Start()
{
if(networkView.isMine == true)
{
myTransform = transform;
networkView.RPC("PVPMove", RPCMode.Server, myTransform.position, myTransform.rotation, myTransform.localScale, PVPC);
}
else
{
enabled = false;
}
}
void Update()
{
if(Vector3.Distance(myTransform.position, lastPosition) >= 0.1)
{
lastPosition = myTransform.position;
networkView.RPC("PVPMove", RPCMode.Server, myTransform.position, myTransform.rotation, myTransform.localScale, PVPC);
}
if(Quaternion.Angle(myTransform.rotation, lastRotation) >= 1)
{
lastRotation = myTransform.rotation;
networkView.RPC("PVPMove", RPCMode.Server,myTransform.position, myTransform.rotation, myTransform.localScale, PVPC);
}
}
[RPC]
void PVPMove(Vector3 newPosition, Quaternion newRotation, Vector3 newScale, NetworkPlayer PlayerC)
{
networkView.RPC("MoveClone", PlayerC, newPosition, newRotation, newScale);
}
[RPC]
void MoveClone(Vector3 newPosition, Quaternion newRotation, Vector3 newScale)
{
myTransform.position = newPosition;
myTransform.rotation = newRotation;
myTransform.localScale = newScale;
}
}
Client:
using UnityEngine; using System.Collections; using System.IO;
public class Client : MonoBehaviour { public static NetworkPlayer PVPC;
[RPC]
void StartPVP(NetworkPlayer Player,int PVPp)
{
if(PVPp == 1)
{
//This is used for the spawn
PVPP = 1;
}
if(PVPp == 2)
{
//This is used for the spawn
PVPP = 2;
}
PVPC = Player;
Application.LoadLevel(3);
}
}
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Smoothing Network Movement with OnSerializeNetworkView 0 Answers
bouncing a puck of a vertical wall through code 0 Answers
Network Trasnform Interpolation Factor 2 Answers
Rocket Jumping Woes 1 Answer