Hi I am trying to connect to Photon Chat but I am not able to connect to it. Rather I am getting disconnected. If I don't put the
if(chatclient!=null)
chatclient.Service();
in the Update loop, it is not getting disconnected, but rather not getting connected as well. Well this is my code
public class PhotonChatController : MonoBehaviour, IChatClientListener
{
void Start()
{
if (string.IsNullOrEmpty(PhotonNetwork.PhotonServerSettings.AppSettings.AppIdChat))
Debug.Log("no CHat app ID provided");
ConnectToPhotonChat();
}
private void ConnectToPhotonChat()
{
chatclient = new ChatClient(this);
chatclient.ChatRegion="in";
chatclient.Connect(PhotonNetwork.PhotonServerSettings.AppSettings.AppIdChat,PhotonNetwork.AppVersion,
new Photon.Chat.AuthenticationValues(nickname));
Debug.Log("Connect to Photon Chat");
}
void Update()
{
if(chatclient!=null)
chatclient.Service();//in the update so that I constantly is connected and receiving messages
}
public void OnDisconnected()
{
Debug.Log("You have disconnected from the Photon Chat........");
}
public void OnConnected()
{
Debug.Log("You have successfully connected to the Photon Chat.......");
chatclient.SendPrivateMessage("chethan7", "INVITE......");
}
Actually speaking in the console "You have successfully connected to the Photon Chat.......",which is the one which gets executed when you successfully connect to Photon Chat should be executed.But that statement is not getting executed at all.
Here is the look of the console:
I got the answer here, hope it helps someone as well
Related
I'm currently using Mirror Networking to make a multiplayer game. I have a scene when players are all connected, they can choose their characters and set the ready. If all players are ready, I change current scene to arena scene using MyNetworkManager.ServerChangeScene(arenaSceneName). This method sets all player clients as not ready. But After the scene was loaded, my player client is no longer connected to my host and I don't know why.
Can you help me please ?
Thanks a lot for answers.
Clients that connect to this server will automatically switch to this scene. This is called automatically if onlineScene or offlineScene are set, but it can be called from user code to switch scenes again while the game is in progress. This automatically sets clients to be not-ready. The clients must call NetworkClient.Ready again to participate in the new scene."
if its not solve problem can you give more information about your project
Are you using MatchInterestManager ? This can be lead some problems like yours
Edit 1 -
Maybe the problem was host
can you run your code on server not host
Edit 2 -
i belive your command function runs on client not server because you miss "Cmd" prefix on your command function change it CmdOnAllPlayersReady()
public class ReadyPlayerChecker : NetworkBehaviour
{
public List<PlayerBehaviour> activePlayers;
public List<PlayerBehaviour> GetActivePlayers()
{
return activePlayers;
}
// Start is called before the first frame update
void Start()
{
activePlayers = new List<PlayerBehaviour>();
}
// Update is called once per frame
void Update()
{
foreach (PlayerBehaviour player in FindObjectsOfType<PlayerBehaviour>
(true))
{
if(!activePlayers.Contains(player))
{
activePlayers.Add(player);
}
}
bool allPlayersReady = true;
foreach (PlayerBehaviour player in activePlayers)
{
if (!player.IsReady())
{
allPlayersReady = false;
}
}
if (allPlayersReady && activePlayers.Count > 0)
{
OnAllPLayersReady();
}
}
[Command]
public void OnAllPLayersReady()
{
GameObject.Find("SceneManager").GetComponent<SceneChanger>
().LoadScene("SimpleArena");
}
}
This is my Network Manager settings :
I succeed to make the playerclient connected when the scene change. Now, the player prefab for my client is in host view but not in the corresponding client view. Do someone can tell me why ?
Hi I have a question about mirror.
I have made a mariokart like game. it works almost perfectly I only have one problem I cant seem to fix.
when I shoot a weapon on the server it works perfectly. On the client it also works when I'm standing still. but when I do it on the client while driving it spawns behind the cart because of syncing or something. How can I fix this?
this is the code
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && hasItem)
{
hasItem = false;
_icon.sprite = null;
CmdFireWeapon();
}
}
[Command]
private void CmdFireWeapon()
{
GameObject item = Instantiate(tempItem, weaponSpawner.position, weaponSpawner.rotation);
NetworkServer.Spawn(item);
}
I am trying to create a simple 2D Turn based multiplayer game using Photon Unity Networking.
It is just a simple turn based game where a player 1 (host) presses his button and it adds his score and changes its turn to player 2 (client) who presses his button to add score and change turn to player 1. It continues to infinite.
I was able to connect two players in the game using the basic Photon documentation. Now I need to add the networking logic of taking turns and changing them.
I searched the internet but I can't understand the RPC and SerializeView of Photon. I am really confused with that. Please Help me. Thank you in future. Here is my GameManager Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : Photon.PunBehaviour
{
public Text roomName;
public Text player1Name,player2Name;
public List<string> playersConnected = new List<string>();
int scoreP1 = 0, scoreP2 = 0;
public Text scoreTextP1, scoreTextP2;
public Button p1Btn, p2Btn;
int playerTurn = 1;
void Start()
{
roomName.text = SceneManager.GetActiveScene().name;
p2Btn.gameObject.SetActive(false);
p1Btn.gameObject.SetActive(true);
}
public void AddScoreP1()
{
scoreP1++;
scoreTextP1.text = scoreP1.ToString();
ChangePlayerTurn();
}
public void AddScoreP2()
{
scoreP2++;
scoreTextP2.text = scoreP2.ToString();
ChangePlayerTurn();
}
void ChangePlayerTurn()
{
if (playerTurn == 1)
{
playerTurn = 2;
p2Btn.gameObject.SetActive(true);
p1Btn.gameObject.SetActive(false);
}
else
{
playerTurn = 1;
p1Btn.gameObject.SetActive(true);
p2Btn.gameObject.SetActive(false);
}
print("Player Turn: P" + playerTurn);
}
void LoadArena()
{
if (!PhotonNetwork.isMasterClient)
{
Debug.LogError("PhotonNetwork : Trying to Load a level but we are not the master Client");
}
Debug.Log("PhotonNetwork : Loading Level : " + PhotonNetwork.room.PlayerCount);
PhotonNetwork.LoadLevel("Room for " + PhotonNetwork.room.PlayerCount);
}
public override void OnLeftRoom()
{
SceneManager.LoadScene(0);
}
public void LeaveRoom()
{
PhotonNetwork.LeaveRoom();
}
public override void OnPhotonPlayerConnected(PhotonPlayer other)
{
Debug.Log("OnPhotonPlayerConnected() " + other.NickName); // not seen if you're the player connecting
foreach (PhotonPlayer _player in PhotonNetwork.playerList)
{
playersConnected.Add(other.NickName);
}
if (PhotonNetwork.isMasterClient)
{
Debug.Log("OnPhotonPlayerConnected isMasterClient " + PhotonNetwork.isMasterClient); // called before OnPhotonPlayerDisconnected
LoadArena();
}
}
public override void OnPhotonPlayerDisconnected(PhotonPlayer other)
{
Debug.Log("OnPhotonPlayerDisconnected() " + other.NickName); // seen when other disconnects
foreach (PhotonPlayer _player in PhotonNetwork.playerList)
{
playersConnected.Remove(other.NickName);
}
if (PhotonNetwork.isMasterClient)
{
Debug.Log("OnPhotonPlayerDisonnected isMasterClient " + PhotonNetwork.isMasterClient); // called before OnPhotonPlayerDisconnected
LoadArena();
}
}
}
RPC is basically a way of invoking a function on a remote client.
Usually in a multiplayer setup you'd want your MasterClient to control the flow of the game. So, when two players join a room, what you need to do is from your MasterClient, decide which player goes first and then call a RPC function from MasterClient telling both client whose the first turn is. Then whichever player's turn it is, just activate its button and let them add score (Send RPC to MasterClient as well for that, so that everyone can stay in sync.) and the update turn and tell everyone via another RPC and so on.
though you can also use Events for such cases, they need less preparation to be used.
Both in a nutshell:
RPC, Remote Procedural calls, is used to call a certain method to all or certain clients/users in the same room/level. Example like this, you might want to use RCP to update the teams score if a team scored a goal.
SerializeView is used by PUN to synchronize and read data a few times per second, depending on the serialization rate. Example like this, you will use this to get and read to see each other's data like how much points another player have in realtime.
both of these functions are practically similar, but their use is entirely different.
There is more information about RCP and SerializeView on the Photon Website Link
I try to scan BLE devices in my Windows 10 IOT background (headless) app running on Raspberry PI 3.
I also tried to use BluetoothLEAdvertisementWatcher in a headed app (with UI) on the same RaspBerry PI machine and it worked.
My headless app is the simplest as it can be:
public sealed class StartupTask : IBackgroundTask
{
private readonly BluetoothLEAdvertisementWatcher _bleWatcher =
new BluetoothLEAdvertisementWatcher();
public void Run(IBackgroundTaskInstance taskInstance)
{
_bleWatcher.Received += _bleWatcher_Received;
_bleWatcher.ScanningMode = BluetoothLEScanningMode.Active;
_bleWatcher.Start();
}
private void _bleWatcher_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
{
}
}
_bleWatcher_Received is never hit. Capabilities are set (Bluetooth, Internet, Proximity).
What is the problem? What do I miss?
You app shuts down when the run method completes. That's why _bleWatcher_Received is never hit.
To prevent you app from exiting you need call the “GetDeferral” method like this:
public void Run(IBackgroundTaskInstance taskInstance)
{
deferral = taskInstance.GetDeferral();
//YOUR CODE HERE
}
For more information please reference "Developing Background Applications".
I'm making a multiplayer game and I'm trying to instantiate a new object on the client. The object should be controlled by that player alone.
I tried it by simply instantiating it on the client, and then spawning it:
public class Player : NetworkBehaviour
{
[SerializeField]
private Card _testCard;
void Update()
{
if (!isLocalPlayer) return;
if (Input.GetKeyDown(KeyCode.Space))
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
{
var card = Instantiate(_testCard);
card.transform.position = hit.point;
card.Name = "Test";
NetworkServer.Spawn(card.gameObject);
//or call this from a command, shown below
}
}
}
/*[Command]
void CmdPlayTestCard(string name, Vector3 position)
{
var card = Instantiate(_testCard);
card.transform.position = position;
card.Name = name;
NetworkServer.Spawn(card.gameObject);
}*/
}
This spawns the object on the client, and it can be controlled by it, but doesn't spawn on the server.
I also did the same in a Command and then it is instantiated everywhere but the client can't controll it. The server can however control it.
What is the proper way of doing this? Creating an object that should be controlled by one of the players, rather than the server?
I tried googling it but couldn't find anything.
Thanks!
I found that this is comming in Unity 5.2, the current beta release notes list this as a feature: "Networking: Added support for client-side authority for non-player objects."
So this will be coming in September for everyone.
Oddler, I don't know the answer, but there is a community at irc.freenode.net in the channel #unity3d-unet that might!
In addition, some resources and code snippets are being gathered here:
https://goo.gl/UmBBpM