El juego del Calamar photon conexiones y posiciones

Aquí lo que vamos hacer es hacer un limite de jugadores en nuestro partida, y colocar nuestros jugadores en determinadas posiciones ahora mismo con el post anterior . AQUI….

Podemos entrar en la habitación tantos jugadores como nosotros queramos, así lo que vamos hacer vamos air a la escena 1 donde tenemos nuestro menu

ahora vamos a editar nuestro script , incorporar lo siguiente a nuestro script

con este script, pondríamos máximo dos jugadores y ambos se conectarían a la vez
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; using UnityEngine.UI; using UnityEngine.SceneManagement; public class MANAGER : MonoBehaviourPunCallbacks { public InputField creartext; public InputField Jointtext; public const int maxPlayerPerRoom = 2; void Start() { PhotonNetwork.ConnectUsingSettings(); PhotonNetwork.AutomaticallySyncScene = true; } public override void OnConnectedToMaster() { PhotonNetwork.JoinLobby(); } // Start is called before the first frame update public void CreateRomm() { PhotonNetwork.CreateRoom(creartext.text); } public override void OnJoinRandomFailed(short returnCode, string message) { PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = maxPlayerPerRoom }, null); } public void JoinRomm() { PhotonNetwork.JoinRoom(Jointtext.text); } public override void OnPlayerEnteredRoom(Player newPlayer) { PhotonNetwork.CurrentRoom.IsOpen = false; Debug.Log(«Ya estanos todos»); PhotonNetwork.LoadLevel(«Game»); } }

Ahora vamos a la escena donde comenzara nuestro juego vamos a establecer las pocisiones

Vamos a nuestro script

Lo vamos a borrar y vamos a incorporar el siguiente
y ponemos este script con este script llamaríamos a nuestros personajes, ahora solo queda poner en que lugar salen nuestros personajes
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using UnityEngine.SceneManagement; public class ConecteServer : MonoBehaviourPunCallbacks { public Transform spaPoint01, spaPoint02; private void Awake() { if (PhotonNetwork.IsMasterClient) { PhotonNetwork.Instantiate(«PLAYER», spaPoint01.position, spaPoint01.rotation); } else { PhotonNetwork.Instantiate(«PLAYER02», spaPoint02.position, spaPoint02.rotation); } } }

Ahora os pondré el Script del personaje, pero no es el que utilizaremos para nuestro juego

using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; public class ci : MonoBehaviourPunCallbacks { public float speed; private Rigidbody2D rb; private Vector2 moveVelocity; // Start is called before the first frame update void Start() { rb = GetComponent(); } // Update is called once per frame void Update() { PhotonNetwork.AutomaticallySyncScene = false; if (photonView.IsMine) { ProcessInputs(); } } private void ProcessInputs() { Vector2 moveInput = new Vector2(Input.GetAxisRaw(«Horizontal»), Input.GetAxisRaw(«Vertical»)); moveVelocity = moveInput.normalized * speed; } void FixedUpdate() { rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime); } }

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *