Hi everyone, I’m talking about Brazil, I apologize for my English!
I am trying to make a game in multiplayer 2d, but I have a doubt that would be in the flip of the player!
The players can not see each other, and are only spawned when the two are connected in the room, I will leave my code below, thank you from now on!
I apologize if the code does not make sense because I am a beginner in the area of multiplayer, and I could not find good tutorials!
SCRIPT HERE!
public class PlayerBehaviour : NetworkBehaviour {
[SyncVar] public bool positionFlip;
void FixedUpdate (){
if (speed < 0) {
if (isServer) {
RpcFacingCallback (true);
} else {
CmdFacingCallback (true);
}
audio.clip = WalkSound;
if (InAndroid == true) {
isRunning = true;
}
}
if (speed > 0) {
audio.clip = WalkSound;
if (InAndroid == true) {
isRunning = true;
}
if (isServer) {
RpcFacingCallback (false);
} else {
CmdFacingCallback (false);
}
}
}
[ClientRpc]
void RpcFacingCallback (bool positionToFlip){
positionFlip = positionToFlip;
if (positionFlip) {
transform.localEulerAngles = new Vector3 (0, 180, 0);
}else{
transform.localEulerAngles = new Vector3 (0, 0, 0);
}
}
[Command]
void CmdFacingCallback (bool positionToFlip){
positionFlip = positionToFlip;
if (positionFlip) {
transform.localEulerAngles = new Vector3 (0, 180, 0);
} else {
transform.localEulerAngles = new Vector3 (0, 0, 0);
}
}