Is it possible to do this?
Hello, I'm trying to make a personal game for me and my friends, and i have a button where i want to turn off fog, small players and big players, How is it possible to do that (Players have tags remote and player so i want to do change their size by not just getting the prefab name but only the tags)
0
Best Answer
-
Lets say you have a game with weather patterns, you mentioned fog. You need a way to send/sync the weather across all players, so one way would be to create an int for each weather type, lets say int 0 = fog off, and int 1 = fog on. (Another way would be via rpc).
So in your networking script that sends/syncs data (ints) to all players you do something like:
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using UnityEngine.UI;
public class MyNetworking : MonoBehaviourPunCallbacks, IPunObservable
{
public int WeatherFog = 0;
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(WeatherFog);
}
else
{
WeatherFog = (int)stream.ReceiveNext();
}
//do you want all players to be able to switch fog on/off - change to if(PhotonNetwork.isMasterClient ) etc etc if only the master controls the weather....
switch (WeatherFog)
{
case 0:
//turn fog off - your own code..
WeatherFog = 2; //change from 0 or 1 to 2 to ensure the switch only runs once.
break;
case 1:
//turn fog on - your own code..
WeatherFog = 2; //change from 0 or 1 to 2 to ensure the switch 0/1 only runs once.
break;
case 2:
break;
}
}
}
Does that give you enough of a clue on how to sync something to all players, then run code when the int changes ?
Regards
Carme
5
Answers
-
hello??0
-
i wanna know how to do this please0
-
please?0
-
i wanna make this pleaseeeeeeeee0
-
Lets say you have a game with weather patterns, you mentioned fog. You need a way to send/sync the weather across all players, so one way would be to create an int for each weather type, lets say int 0 = fog off, and int 1 = fog on. (Another way would be via rpc).
So in your networking script that sends/syncs data (ints) to all players you do something like:
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using UnityEngine.UI;
public class MyNetworking : MonoBehaviourPunCallbacks, IPunObservable
{
public int WeatherFog = 0;
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(WeatherFog);
}
else
{
WeatherFog = (int)stream.ReceiveNext();
}
//do you want all players to be able to switch fog on/off - change to if(PhotonNetwork.isMasterClient ) etc etc if only the master controls the weather....
switch (WeatherFog)
{
case 0:
//turn fog off - your own code..
WeatherFog = 2; //change from 0 or 1 to 2 to ensure the switch only runs once.
break;
case 1:
//turn fog on - your own code..
WeatherFog = 2; //change from 0 or 1 to 2 to ensure the switch 0/1 only runs once.
break;
case 2:
break;
}
}
}
Does that give you enough of a clue on how to sync something to all players, then run code when the int changes ?
Regards
Carme
5