[RESOLVIDO] Preciso de uma ajuda com PUM v1
SchultzGames :: UNITY 3D :: Resolvidos
Página 1 de 1
[RESOLVIDO] Preciso de uma ajuda com PUM v1
Olá, estava utilizando o photonnetwork, porém chegou em uma parte que eu não estou conseguindo fazer funcionar do jeito que quero. Gostaria de instanciar um player para cada jogador, mas simplesmente não consigo. O host da sala acaba sempre sendo o unico a ter player.
- Código:
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerNetwork : MonoBehaviour
{
public static PlayerNetwork Instance;
public string PlayerName{ get; private set; }
private PhotonView PhotonView;
private int PlayersInGame = 0;
public GameObject SpawnSpot;
private void Awake()
{
Instance = this;
PhotonView = GetComponent<PhotonView>();
PlayerName = "RGBOT#" + Random.Range(1000, 9999);
SceneManager.sceneLoaded += OnSceneFinishedLoading;
}
private void OnSceneFinishedLoading(Scene scene, LoadSceneMode mode)
{
if(scene.name == "mundo")
{
if (PhotonNetwork.isMasterClient)
MasterLoadedGame();
else
NonMasterLoadedGame();
}
}
private void MasterLoadedGame()
{
PhotonView.RPC("RPC_LoadedGameScene", PhotonTargets.MasterClient);
PhotonView.RPC("RPC_LoadGameOthers", PhotonTargets.Others);
}
private void NonMasterLoadedGame()
{
PhotonView.RPC("RPC_LoadedGameScene", PhotonTargets.MasterClient);
}
[PunRPC]
private void RPC_LoadGameOthers()
{
PhotonNetwork.LoadLevel(1);
}
[PunRPC]
private void RPC_LoadedGameScene()
{
PlayersInGame++;
if (PlayersInGame == PhotonNetwork.playerList.Length)
{
print("All players are in the game scene.");
}
SpawnSpot = GameObject.FindGameObjectWithTag("T1");
GameObject Gira = GameObject.FindGameObjectWithTag("T2");
if (PhotonView.isMine)
{
GameObject MyPlayerGO = PhotonNetwork.Instantiate(System.IO.Path.Combine("Prefabs", "NewPlayer"), SpawnSpot.transform.position, SpawnSpot.transform.rotation, 0);
MyPlayerGO.transform.parent = Gira.transform;
MyPlayerGO.GetComponent<FirstPersonAIO>().enabled = true;
GameObject Cam = GameObject.FindGameObjectWithTag("MainCamera");
Cam.GetComponent<Camera>().enabled = true;
Cam.GetComponent<AudioListener>().enabled = true;
}
}
}
yurinogueira- Membro
- PONTOS : 2495
REPUTAÇÃO : 11
Respeito as regras :
Re: [RESOLVIDO] Preciso de uma ajuda com PUM v1
- Código:
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerNetwork : MonoBehaviour
{
public static PlayerNetwork Instance;
public string PlayerName { get; private set; }
private PhotonView PhotonView;
private int PlayersInGame = 0;
public GameObject SpawnSpot;
private void Awake()
{
Instance = this;
PhotonView = GetComponent<PhotonView>();
PlayerName = "RGBOT#" + Random.Range(1000, 9999);
SceneManager.sceneLoaded += OnSceneFinishedLoading;
}
private void OnSceneFinishedLoading(Scene scene, LoadSceneMode mode)
{
if (scene.name == "mundo")
{
if (PhotonNetwork.isMasterClient)
MasterLoadedGame();
else
NonMasterLoadedGame();
}
}
private void MasterLoadedGame()
{
PhotonView.RPC("RPC_LoadedGameScene", PhotonTargets.MasterClient);
PhotonView.RPC("RPC_LoadGameOthers", PhotonTargets.Others);
}
private void NonMasterLoadedGame()
{
PhotonView.RPC("RPC_LoadedGameScene", PhotonTargets.MasterClient);
}
[PunRPC]
private void RPC_LoadGameOthers()
{
PhotonNetwork.LoadLevel(1);
}
[PunRPC]
private void RPC_LoadedGameScene()
{
PlayersInGame++;
if (PlayersInGame == PhotonNetwork.playerList.Length)
{
PhotonView.RPC("RPC_CreatePlayer", PhotonTargets.All);
}
}
[PunRPC]
public void RPC_CreatePlayer()
{
SpawnSpot = GameObject.FindGameObjectWithTag("T1");
GameObject Gira = GameObject.FindGameObjectWithTag("T2");
for (int i = 0; i < PhotonNetwork.playerList.Length; i++)
{
if (PhotonNetwork.playerList.Length == i + 1)
{
GameObject _playerPrefab = (GameObject)PhotonNetwork.Instantiate("Prefabs/NewPlayer", SpawnSpot.transform.position, SpawnSpot.transform.rotation, 0);
if (PhotonView.isMine)
{
_playerPrefab.transform.parent = Gira.transform;
_playerPrefab.GetComponent<FirstPersonAIO>().enabled = true;
GameObject Cam = GameObject.FindGameObjectWithTag("MainCamera");
Cam.GetComponent<Camera>().enabled = true;
Cam.GetComponent<AudioListener>().enabled = true;
}
}
}
}
}
yurinogueira- Membro
- PONTOS : 2495
REPUTAÇÃO : 11
Respeito as regras :
Re: [RESOLVIDO] Preciso de uma ajuda com PUM v1
- Código:
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerNetwork : MonoBehaviour
{
public static PlayerNetwork Instance;
public string PlayerName { get; private set; }
private PhotonView PhotonView;
private int PlayersInGame = 0;
public GameObject SpawnSpot;
private FirstPersonAIO CurrentPlayer;
private void Awake()
{
Instance = this;
PhotonView = GetComponent<PhotonView>();
PlayerName = (PlayerPrefs.GetString("Nome")) + ("#") + (Random.Range(1000, 9999));
SceneManager.sceneLoaded += OnSceneFinishedLoading;
}
private void OnSceneFinishedLoading(Scene scene, LoadSceneMode mode)
{
if (scene.name == "mundo")
{
if (PhotonNetwork.isMasterClient)
MasterLoadedGame();
else
NonMasterLoadedGame();
}
}
private void MasterLoadedGame()
{
PhotonView.RPC("RPC_LoadedGameScene", PhotonTargets.MasterClient, PhotonNetwork.player);
PhotonView.RPC("RPC_LoadGameOthers", PhotonTargets.Others);
}
private void NonMasterLoadedGame()
{
PhotonView.RPC("RPC_LoadedGameScene", PhotonTargets.MasterClient, PhotonNetwork.player);
}
[PunRPC]
private void RPC_LoadGameOthers()
{
PhotonNetwork.LoadLevel(2);
}
[PunRPC]
private void RPC_LoadedGameScene(PhotonPlayer photonPlayer)
{
PlayersInGame++;
if (PlayersInGame == PhotonNetwork.playerList.Length)
{
PhotonView.RPC("RPC_CreatePlayer", PhotonTargets.All);
}
}
[PunRPC]
public void RPC_CreatePlayer()
{
SpawnSpot = GameObject.FindGameObjectWithTag("T1");
GameObject Gira = GameObject.FindGameObjectWithTag("T2");
for (int i = 0; i < PhotonNetwork.playerList.Length; i++)
{
if (PhotonNetwork.playerList.Length == i + 1)
{
GameObject _playerPrefab = PhotonNetwork.Instantiate("Prefabs/NewPlayer", SpawnSpot.transform.position, SpawnSpot.transform.rotation, 0);
GameObject Cam = GameObject.FindGameObjectWithTag("MainCamera");
Cam.GetComponent<Camera>().enabled = true;
Cam.GetComponent<AudioListener>().enabled = true;
CurrentPlayer = _playerPrefab.GetComponent<FirstPersonAIO>();
}
}
}
}
yurinogueira- Membro
- PONTOS : 2495
REPUTAÇÃO : 11
Respeito as regras :
Tópicos semelhantes
» [RESOLVIDO] Ajuda com o IEnumerator... SERIAO MSM, Preciso de ajuda.
» [RESOLVIDO] PRECISO DE AJUDA COM SCRIPTS
» [RESOLVIDO] Preciso de ajuda com joystic para personagem 2D
» [RESOLVIDO] Preciso de ajuda para fazer um objeto pegar fogo!
» [AJUDA]Preciso de ajuda em um script relacionado ao vídeo Sistema de escolha de personagen
» [RESOLVIDO] PRECISO DE AJUDA COM SCRIPTS
» [RESOLVIDO] Preciso de ajuda com joystic para personagem 2D
» [RESOLVIDO] Preciso de ajuda para fazer um objeto pegar fogo!
» [AJUDA]Preciso de ajuda em um script relacionado ao vídeo Sistema de escolha de personagen
SchultzGames :: UNITY 3D :: Resolvidos
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos