help-me
Options
Hello, how are you?
I'm having some problems creating my game using the photon, I created 2 scripts, one that does all the checking if the player is in a room, or if it doesn't exist and the other controls the player.
But when the player logs into the room and the scene loads, I can't see any of the connected players.
Code one:
Second Code:
player connected:
problems:
1- players do not appear to each other
2- player connected is duplicated
I'm having some problems creating my game using the photon, I created 2 scripts, one that does all the checking if the player is in a room, or if it doesn't exist and the other controls the player.
But when the player logs into the room and the scene loads, I can't see any of the connected players.
Code one:
using UnityEngine; using UnityEngine.UI;[img]https://pasteboard.co/Jcrjf5T.png[/img] using Photon.Pun; using Photon.Realtime; namespace Com.JODIF.GameJodif { public class launcher : MonoBehaviourPunCallbacks { #region Public object public int maxPlayersPerRoom = 4; public Text texto; #endregion #region Private Fields /// <summary> /// Aqui temos a versão do game no qual o jogador vai se conectar. /// </summary> string gameVersion = "1"; bool isConnecting; #endregion #region MonoBehaviour CallBacks /// <summary> ///metodo de retorno do Monobehavior /// </summary> void Awake() { // #Critical // Faz com que as cenas sejam syncadas para todos os players ao mesmo tempo. PhotonNetwork.AutomaticallySyncScene = true; } private void Start() { Connect(); } #endregion #region Public Methods /// <summary> /// Inicia o processo de conecção /// - Se estiver conectado ele conecta a uma sala aletoria. /// - Se não, ele conecta a nuvem do Photon. /// </summary> public void Connect() { // Ele vai checar se está conectado ou não if (PhotonNetwork.IsConnected) { // esse é um ponto critico, pois se não possuir nenhuma sala disponivel ele ira precisar de um metodo: OnJoinRandomFalied(). PhotonNetwork.JoinRandomRoom(); } else { // Ele se conectará a photon cloud para gerar poder ser efetuada a conexão do player ao game. isConnecting=PhotonNetwork.ConnectUsingSettings(); PhotonNetwork.GameVersion = gameVersion; } } #endregion #region MonoBehaviourPunCallbacks Callbacks public override void OnConnectedToMaster() { Debug.Log("O player foi conectado ao PhotonMaster"); texto.text = "Connectando..."; if (isConnecting) { PhotonNetwork.JoinRandomRoom();isConnecting = false; } } public override void OnDisconnected(DisconnectCause cause) { isConnecting = false; Debug.LogWarningFormat("O player foi desconectado do Photon master por:", cause); } public override void OnJoinRandomFailed(short returnCode, string message) { texto.text = "Nenhuma sala encontrada...Criando uma."; Debug.Log("O player não conectou a nenhuma sala, então uma será criada."); // como conectar em alguma sala falhou, ele criará uma para o player. PhotonNetwork.CreateRoom(null, new RoomOptions()); } public override void OnJoinedRoom() { texto.text = "Conectado a Sala."; Debug.Log("Player conectou a sala."); PhotonNetwork.LoadLevel(1); } #endregion } }(this code taken from the PUN tutorial)
Second Code:
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Photon.Pun; public class Palyer : MonoBehaviour { public float maxSpeed; public float forceJump; private bool grounded; private bool spike; private bool jumping; public Transform groundcheck; private Rigidbody2D rd2d; private Animator anim; private SpriteRenderer sprite; void Awake () { rd2d = GetComponent<Rigidbody2D>(); sprite = GetComponent<SpriteRenderer>(); anim = GetComponent<Animator>(); } void Update () { grounded = Physics2D.Linecast(transform.position, groundcheck.position, 1 << LayerMask.NameToLayer("ground")); spike = Physics2D.Linecast(transform.position, groundcheck.position, 1 << LayerMask.NameToLayer("spike")); if (Input.GetButtonDown("Jump") && grounded) { jumping = true; } } void FixedUpdate() { float movi = Input.GetAxis("Horizontal"); anim.SetFloat("speed",Mathf.Abs(movi)); rd2d.velocity = new Vector2(movi * maxSpeed, rd2d.velocity.y); if ((movi>0f && sprite.flipX)||(movi< 0f && !sprite.flipX)) { Flip(); } if (jumping) { rd2d.AddForce(new Vector2(0f,forceJump)); jumping = false; } anim.SetBool("jumpfall",rd2d.velocity.y!=0f); } void Flip() { sprite.flipX = !sprite.flipX; } }master client:
player connected:
problems:
1- players do not appear to each other
2- player connected is duplicated
0