Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all 8947 articles
Browse latest View live

Discord room invites

$
0
0
It would be really nice if my game allows people to invite to a room via discord, might be available somehow, but I don’t know how :(

How to use prefab pool in PUN2 ! (network optimization to avoid deconnection)

$
0
0
Hello,

This is not a question but a solution for those who struggle to understand what is a prefab pool and how to use it with PUN2 (since i've been through, I share!)

In order to optimize the networking system and avoid disconnection issues, I read that it is better to use prefab pool instead of using.
PhotonNetwork.Instantiate()
and
PhotonNetwork.Destroy()

It is very usefull to increase the CPU performance and in this case the network performance and avoid disconnection.

If you are not familiar with Object Pooling, here a link to Brackeys Video:
image

Anyway, to avoid also to use PhotonInstantiation in a loop, I prefere to Instantiate all the way and store the GO until it reaches a max value (to avoid traffic)

In this case, the code is made to :
  1. Instantiate a Prefab if the list lenght <50
  2. Recycle a "dead prefab" if the list is >=50 to avoind using Instantiate
public class Spawn : MonoBehaviourPun
{
//Photon
using Photon.Pun;
using Photon.Realtime;
using ExitGames.Client.Photon;

            private void Spawn()
            {
                Vector3 instantPos = new Vector3(spawnVectorX, spawnVectorY, spawnVectorZ);
                //Instantiate accross the network (never use PUN RPC to spawn)
                PrefabPooler(System.IO.Path.Combine("Creep", ennemyData.ennemyGO.name), instantPos, Quaternion.identity);

            }

        //-------------------------------------------------------------------------------------------//
        //                                     PHOTON PREFAB POOL                                    //
        //-------------------------------------------------------------------------------------------//

        /// <summary>
        /// -CLEV- FOR PHOTON PUN2
        ///An Object Pool can be used to keep and reuse instantiated object instances.
        ///Replaces Unity's default Instantiate and Destroy methods.
        ///Defaults to the DefaultPool type.To use a GameObject pool, 
        ///implement IPunPrefabPool and assign it here. Prefabs are identified by name.
        /// </summary>
        /// 
        /// <param name="prefabId"></param>
        /// <param name="position"></param>
        /// <param name="rotation"></param>
        /// <returns></returns>

        private GameObject PrefabPooler(string prefabId, Vector3 position_i, Quaternion rotation)
        {
            //If our pooler is not full, continue to instantiate a Warden with PUN2
            if (spawnPrefabArray.Count < maxPoolSize)
            {
                ennemySpawn = PhotonNetwork.Instantiate(System.IO.Path.Combine("Creep", ennemyData.ennemyGO.name), position_i, Quaternion.identity);
                spawnPrefabArray.Add(ennemySpawn);//add it to the queue
            }
            //Otherwise use the Pool to activate our Wardens
            else
            {
                for(int i = 0; i < spawnPrefabArray.Count; i++)
                {
                    if (spawnPrefabArray[i].GetComponent<LifeSystemNet>().ennemyIsDead)
                    {
                        Debug.Log(spawnPrefabArray[i] + " is recycled");
                        ennemySpawn = spawnPrefabArray[i];
                        ennemySpawn.GetComponent<LifeSystemNet>().ennemyIsDead = false;
                        ennemySpawn.transform.position = position_i;
                        ennemySpawn.SetActive(true);//activate the gameObject
                        break; //stop the loop
                    }

                }
            }

            return ennemySpawn;
        }



}



Instead of using
PhotonNetwork.Destroy()

deactivate the gameobject!
if(ennemySpawn.isDead)
{
   ennemySpawn.SetActive(false);
}

Calculate packet loss percentage

$
0
0
Hello.

How could I retrieve the packet loss percentage? I know that some packets are bundled to a bigger packet for transmission, so I can't simply count them.

There is the PhotonNetwork.NetworkingClient.LoadBalancingPeer.NetworkSimulationSettings.LostPackagesIn command to get the absolute number of lost packages. If I compare that number to PhotonNetwork.NetworkingClient.LoadBalancingPeer.TrafficStatsIncoming.TotalPacketCount often there's a higher incoming packet loss count than there is received packets. How to fix that?

Thank you.

[SOLVED] Problem with synchronizing variable

$
0
0
Hello. I am making a system that has one variable that is synchronzied on every players so they always have the same value.
public int money;

if (Input.GetKeyDown(KeyCode.F))
{
        PhotonView PV = GetComponent<PhotonView>();
        PV.RPC("IncreaseMoney", RpcTarget.All, 5);
}

[PunRPC]
public void IncreaseMoney(int amount)
{
        money += amount;
}


This is code I wrote, but there's a problem. If there's two players and one player increases the variable, it only increases on the player and does not on the other player.

unknown.png

Player1 is joined in unity editor. When Player2 increases money, it should be increased on every player scripts. However, it only increases on Player2. So as you can see, Player1 can see that Player2 has increased the variable but it's not applied to Player1 itself.

What should I do?

Webgl connection problems

$
0
0
Hello everyone, hope you are doing well in these dire times.
I am writing this post because I am having a problem with a WebGL build of my Unity application.
My application works by loading a main menu and OnConnectedToMaster it proceeds to either create a new room or join a random one, loading a new multiplayer scene.
The problem is that on some computers the connection does not happen. It remains stuck on the first scene like it cannot join or create a room.
This problem happens on a computer of a person I do not have direct contact with, so it's kinda hard to debug, but I managed to make them send a log file to me and this is what I get:

Aumakua.loader.js:280 [UnityCache] './Build/Aumakua.data' successfully downloaded and stored in the indexedDB cache
Aumakua.loader.js:31 still waiting on run dependencies:
printErr @ Aumakua.loader.js:31
Aumakua.loader.js:31 dependency: wasm-instantiate
printErr @ Aumakua.loader.js:31
Aumakua.loader.js:31 (end of list)
printErr @ Aumakua.loader.js:31
/master/Build/Aumakua.framework.js:3357 PlayerConnection initialized from (debug = 0)

/master/Build/Aumakua.framework.js:3357 PlayerConnection disabled - listening mode not supported

/master/Build/Aumakua.framework.js:3357 Started listening to [0.0.0.0:0]

/master/Build/Aumakua.framework.js:3357 PlayerConnection already initialized - listening to [0.0.0.0:0]

/master/Build/Aumakua.framework.js:3357 Loading player data from data.unity3d

/master/Build/Aumakua.framework.js:3357 Initialize engine version: 2020.2.1f1 (270dd8c3da1c)

Aumakua.loader.js:28 Creating WebGL 2.0 context.
/master/Build/Aumakua.framework.js:3357 Renderer: WebKit WebGL

/master/Build/Aumakua.framework.js:3357 Vendor: WebKit

/master/Build/Aumakua.framework.js:3357 Version: OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium))

/master/Build/Aumakua.framework.js:3357 GLES: 3

/master/Build/Aumakua.framework.js:3357 EXT_color_buffer_float GL_EXT_color_buffer_float EXT_color_buffer_half_float GL_EXT_color_buffer_half_float EXT_disjoint_timer_query_webgl2 GL_EXT_disjoint_timer_query_webgl2 EXT_float_blend GL_EXT_float_blend EXT_texture_compression_bptc GL_EXT_texture_compression_bptc EXT_texture_compression_rgtc GL_EXT_texture_compression_rgtc EXT_texture_filter_anisotropic GL_EXT_texture_filter_anisotropic EXT_texture_norm16 GL_EXT_texture_norm16 KHR_parallel_shader_compile GL_KHR_parallel_shader_compile OES_texture_float_linear GL_OES_texture_float_linear WEBGL_compressed_texture_s3tc GL_WEBGL_compressed_texture_s3tc WEBGL_compressed_texture_s3tc_srgb GL_WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info GL_WEBGL_debug_renderer_info WEBGL_debug_shaders GL_WEBGL_debug_shaders WEBGL_lose_context GL_WEBGL_lose_context WEBGL_multi_draw GL_WEBGL_multi_draw OVR_multiview2 GL_OVR_multiview2

Aumakua.framework.js:13235 WebGL: INVALID_ENUM: getInternalformatParameter: invalid internalformat
_glGetInternalformativ @ Aumakua.framework.js:13235
Aumakua.framework.js:13235 WebGL: INVALID_ENUM: getInternalformatParameter: invalid internalformat
_glGetInternalformativ @ Aumakua.framework.js:13235
Aumakua.framework.js:13235 WebGL: INVALID_ENUM: getInternalformatParameter: invalid internalformat
_glGetInternalformativ @ Aumakua.framework.js:13235
/master/Build/Aumakua.framework.js:3357 OPENGL LOG: Creating OpenGL ES 3.0 graphics device ; Context level <OpenGL ES 3.0> ; Context handle 20683424


/master/Build/Aumakua.framework.js:3357 UnloadTime: 1.715000 ms

/master/Build/Aumakua.framework.js:6189 warning: 2 FS.syncfs operations in flight at once, probably just doing extra work
/master/Build/Aumakua.framework.js:3357 Input Manager initialize...

Aumakua.framework.js:3813 WebSocket connection to 'wss://ns.exitgames.com:19093/' failed: WebSocket opening handshake timed out
_SocketCreate @ Aumakua.framework.js:3813
Aumakua.loader.js:31 writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!
printErr @ Aumakua.loader.js:31
/master/Build/Aumakua.framework.js:3350 Exiting receive thread. Server: wss://ns.exitgames.com:19093:0 Error: Abnormal disconnection.



_JS_Log_Dump @ /master/Build/Aumakua.framework.js:3350


It seems like the bold parts are the problem but I have no idea how to make it work.

If you guys know something about this please let me know!
Thank you in advance and have a great day!

URGENT, Connection Problem

$
0
0
Is there any problem with server? I cannot connect to Photon.
Thanks

Rooms not visible in WebGL build

$
0
0
I've been working on a multiplayer game with a custom matchmaking system. similar to the one setup in InfoGamer's YouTube video (image

Everything seems to work as a regular Windows build; players can create rooms, and other players can join those rooms or make their own. Recently I've been trying to create a webGL version of the game for easier access. It seemed to work about a month ago, but as of late, rooms are no longer visible to players that are on different computers. However, if I try to play the game on one computer by using multiple Chrome tabs to emulate several players, I am able to view rooms created by others.

Some additions have been made to room properties within coding, so I thought maybe there was some issue on the code side, but when I build the game for Windows as a standalone, I'm able to connect to other machines through the network. This makes me think there is something wrong with the way I am building the game for WebGL that makes rooms not visible. I've checked my region settings, and they appear to be consistent.

Has anyone else experienced this issue or found any resolution? This seems to have happened suddenly, and without a clear cause.

For what it's worth, I was able to connect with other people via a WebGL build about a month ago, but it doesn't seem to work anymore. I've even tried my older build that worked in the past and it doesn't seem to work anymore. I'm using Simmer.IO to host my game.

Thanks!
Ben

¿How do i make tactile buttons for android?

$
0
0
I'm trying to make a online android game, but when i make the buttons scripts like in my other games, the prefab for the character doesn't move how it's supposed to.

Sending basic information across the network is failing? *SOLVED*

$
0
0
Hi, I'm trying to send some basic information about each individual player across the network.
For reference, I understand custom properties, but later on, this script will carry much more data with various variables that change frequently. Health,ping and other things.

I'm trying to send the data across the network using 'OnPhotonSerializeView'. So all players can see the information in the script.

The purpose of this script is that I can get access to each players information fairly easily by passing the viewID of the player and then using 'getcomponent<Player_Information>();'

The OnPhotonSerializeView doesn't seem to run until there are multiple players in the game. That makes sense and is fine.
But the errors I get are:
'Error: you cannot read this stream that you are writing!'
It also throws and null reference error on the: 'PlayerPing = (int)stream.ReceiveNext();' line.

What am I fundamentally doing wrong here?

The script is in the observable photonview. The script is also attached to the player. The photonview is on the same object as this script.

I even looked through the sample files, they all seem to do what I'm trying to achieve in the same way.

Am I missing something?Am I being a complete idiot?

I hope someone can explain and put me in right direction.

Thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class Player_Information : MonoBehaviourPun, IPunObservable
{
    // Start is called before the first frame update
    [SerializeField]
    string PlayerName;
    [SerializeField]
    int PlayerPing;

    [SerializeField]
    string PlayerTeam;

    public Network_Character NC_Script;
    bool Update_Ping = true;

    bool Update_Info = true;


    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (PhotonNetwork.IsConnected && GetComponent<PhotonView>().IsMine == false)
        {

            return;
        }


        //empty name
        if (PlayerName.Length == 0)
        {
            Update_Name();
        }

        if (PlayerTeam.Length == 0)
        {
            Update_Team();
        }

        if (Update_Ping)
        {

            StartCoroutine(Update_Players_Ping());

        }




    }


    void Update_Team()
    {
        if (NC_Script.IsHuman)
        {
            PlayerTeam = "Team Blue";
        }
        else
        {
            PlayerTeam = "Team Red";
        }
    }

    void Update_Name()
    {
        PlayerName = PlayerPrefs.GetString("nickname");

    }


    IEnumerator Update_Players_Ping()
    {
        Update_Ping = false;
        //update ping every 3 seconds
        while (true)
        {
            PlayerPing = PhotonNetwork.GetPing();

            yield return new WaitForSecondsRealtime(3);

        }


    }


    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        { //This is if I am sending data to the server
            stream.SendNext(PlayerPing);
        }
        else
        { // if I am not sending data to the server then I must be receiving data
            PlayerPing = (int)stream.ReceiveNext();
        }
    }

}

OnPhotonInstantiate not called

$
0
0
For some reaseon OnPhotonInstantiate is not being called when instatiated. OnEnabled IS beaing called so the object is instantiated and created in scene, but OnPhotonInstantiate is not being called
I am using PUN 2

I do not know why this is happening, I even implemented IPunInstantiateMagicCallback.


This is the code where OnPhotonInstantiate should get called
public class yoyoUlt : MonoBehaviour, IPunInstantiateMagicCallback
{
    public float yoyoFast = 10, spinSpeed = 10, maxSpinSpeed = 10;
    private float scale;
    public Transform yoyoChild;
    private Vector3 playerScale;
    object[] instData;
    
    // Start is called before the first frame update
    void OnEnable()
    {
      transform.localScale = new Vector3(playerScale.x, 1, 1);
      scale = playerScale.x;
    }

    public void OnPhotonInstantiate(PhotonMessageInfo info)
    {
        Debug.Log("Instantiated");
        instData = info.photonView.InstantiationData;
        playerScale = (Vector3)instData[0];
        Debug.Log("inst data " + playerScale);
    }

This is instantiate code
        object[] yoyoOwnerPlayerData = new object[1];
        yoyoOwnerPlayerData[0] = DukeParent.transform.localScale; 
 PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "YoyoUlt"), yoyoOrig.transform.position, Quaternion.identity, 0, yoyoOwnerPlayerData);
 

Particle collisions/ collision in general

$
0
0
So i have most the game working i just have a problem with particle collisions. On your machine it shows it colliding, the other it goes through, i am not sure where to add or change something, please help!!

Rejoined an empty room with EmptyRoomTtl = 0

$
0
0
Hi Photon folks,

I am working on an application where we are using Photon Rooms with EmptyRoomTtl set to 0. However, I was investigating a bug and noticed we have a (rare) scenario where all users leave a room, and a subsequent JoinOrCreateRoom with the same name is joining the same room instance that was left empty, reinstantiating some PhotonViews.

I'm wondering if our code is holding references to PhotonViews in that room, but looking at the documentation, the room is considered empty when all users leave, not when all content is removed. Is there another explanation that could cause an empty room to stick around?

Interestingly enough, I'm looking through the Photon code and I don't see EmptyRoomTtl used anywhere, and it's probably worth mentioning that we're using CleanupCacheOnLeave = false in order to keep a user's content around after they exit.

Also worth noting it appears from the logs that the user joined and was not deemed master client, although there were no other users, which makes me think someone failed to leave the room when disconnecting. I see that our code doesn't check the return value of PhotonNetwork.LeaveRoom. What are the reasons PhotonPeer.SendOperation(OperationCode.Leave, opParameters, SendOptions.SendReliable) would fail? If that was our issue, what do we do in this case? Simply retry?

Thanks!

[PUN 2] Change MeshFilter and MeshRenderer with RPC

$
0
0
Hi! I'm new to Photon and a bit rusty with C#, I'm trying to create a simple Prop Hunt: players should be able to change their appearance by interacting with objects in the scene, changing their mesh and materials with the ones of the objects. Of course, I have to communicate this to other players.
I thought I could use an RPC like this:
//with a raycast i interacted with the right object and now i'm 
and now I'm collecting the info I need to change mesh and material
if (Physics.Raycast(ray, out RaycastHit hit))
        {
            GameObject tempHit = hit.collider.gameObject;
            if (tempHit.GetComponent<Prop>())
            {
               PV.RPC("RPC_PropChangeModel", RpcTarget.All, tempHit);
            }
        }
[...]
[PunRPC]
    void RPC_PropChangeModel(GameObject temp)
    {
        if (!PV.IsMine)
            return;

        gameObject.GetComponent<MeshFilter>().mesh = temp.GetComponent<MeshFilter>().mesh;
        gameObject.GetComponent<MeshRenderer>().material = temp.GetComponent<MeshRenderer>().material;
    }


This is not working, I keep getting this error message in console:
Exception: Write failed. Custom type not found: UnityEngine.GameObject
ExitGames.Client.Photon.Protocol18.WriteCustomType (ExitGames.Client.Photon.StreamBuffer stream, System.Object value, System.Boolean writeType)


How can I make this work? I can't find help online. Thx!

Implementing multilplayer in a strategic game using Photon

$
0
0
Hello guys,

I've been working on my second project as a beginner game dev and I though on making a small scope game. I also wanted to try making it multiplayer and after a bit of research I found out mirror and Photon as good resources to get it done.

After some tutorials and documentation I am a bit confused because I haven't found some way to implement my expected game flow inside my game.

ABOUT MY GAME:

There are two teams and one has to survive, killing the enemy team. In order to that, players can move around the map and throw a rock. The "interesting" thing about this is that players have a "Think Phase", where they can move around and it's not seen by any player, and set its throw. After the think phase, it begins the "Action Phase", players first move and set its position and then they throw the rock.

MY THOUGHTS

As I see it, it's an asynchronous call. For that I want my players to "synchronize" movement after think phase and then throw the rock.

Also, I don't know exactly how should I store local movements from player (using a queue? sounds weird because i use AddForce for playerMovement...).

The tutorials I've found explain real-time synchronization and the few of them which explain turn-based games doesn't exactly match my game flow.

I also tried the rock, paper and scissors example which uses Photon but I haven't gotten anything clear.

Maybe I shouldn't have picked Photon? Any thoughts about this?

TL;DR: How should I implement a "think phase" and a "do-phase" using Photon? Think-phase = local movement + throw set, do-phase = "synchronize" for other players

An example how they game I want it to look like: image

(Yes, it's a "copy" of this game, but I want to change and add some things)

CCU user vs active user

$
0
0
hello,
I have a game where players connect to a room to get a task, example coloring. But once the task is assigned, players perform the task without any interaction with server i.e. unity handles the rest of things. The game ends when the first person completes his task, and announced winner. So the room has to be intact but players are idle from photon perspective. In such cases, how does photon handle CCU vs active user? Or can I optimally handle such interactions, and save on CCU usage?

Thanks

Photon + Steam friends

$
0
0
Hello, does Photon support inviting friends to a Photom room? I looked around and couldn't find much. At most I found that you can use SteamFreinds.InviteUserToGame with a room name included as the second parameter, but when the user launches the game, steam sends a warning that they're launching the game with command line parameters.

Any saviour know how handle this?

Photon Room List - Sort By & Filter

$
0
0
Hello everyone.

So i've hit a snag and hoping to get some advice as i'm only a hobbist when it comes to coding.

I've currently setup up Playfab for authentication and Photon for my multiplayer servers. I've got the whole UI menu working great, I can create rooms with custom options for PvE and PvP, public or private servers etc. Now when it comes to showing the list of current servers I've got that working as I want as well BUT now comes the tricky part.

I want to be able to sort the list of rooms alphabetically by either name, game mode or server type. Optionally I want to be able to sort the rooms numerically by the amount of players in each room.

The other things I want to be able to do is then search the rooms by name.

Oh and to make things even more complicated I want to be able to then filter either by game mode, server type or full/not full rooms.

I've tried hunting for tutorials or hints everywhere but coming up short.

This is my UI;

https://ibb.co/c6dXCD7

As you can see im using a Scroll Rect with Prefabs for the list with each room being instantiated as a button so I can select and join that room.

My code so far is;

public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
base.OnRoomListUpdate(roomList);
int tempIndex;
foreach(RoomInfo room in roomList)
{
if(joinRoomListings != null)
{
tempIndex = joinRoomListings.FindIndex(ByName(room.Name));
}
else
{
tempIndex = -1;
}
if(tempIndex != -1)
{
joinRoomListings.RemoveAt(tempIndex);
Destroy(joinRoomPanel.GetChild(tempIndex).gameObject);
}
else
{
joinRoomListings.Add(room);
ListRoom(room);
}
}
}

public void RemoveRoomListings()
{
int i = 0;
while (joinRoomPanel.childCount != 0)
{
Destroy(joinRoomPanel.GetChild(i).gameObject);
i++;
}
}

static System.Predicate<RoomInfo> ByName(string name)
{
return delegate (RoomInfo room)
{
return room.Name == name;
};
}

public void ListRoom(RoomInfo room)
{
//if(room.IsOpen && room.IsVisible)
if ((string)room.CustomProperties["GameMode"] == "PvP")
{
GameObject tempListing = Instantiate(joinRoomPrefab, joinRoomPanel);
RoomButton tempButton = tempListing.GetComponent<RoomButton>();
tempButton.roomName = room.Name;
tempButton.gameMode = (string)room.CustomProperties["GameMode"];
tempButton.playerCount = room.PlayerCount + "/" + room.MaxPlayers;
tempButton.server = (string)room.CustomProperties["Server"];
tempButton.SetRoom();
}
}

public void FilterOptions()
{
Room.Name == Variable;
(string)room.CustomProperties["GameMode"] == "PvE"
(string)room.CustomProperties["GameMode"] == "PvP"
room.PlayerCount < room.MaxPlayers
room.PlayerCount == room.MaxPlayers
(string)room.CustomProperties["Server"] == "Public"
(string)room.CustomProperties["Server"] == "Private"
}

Any help, hints or tips etc would be appreciated on the most efficient way to do this.

Thanks all.

Is it recommended to have a "cross-plattform" Windows- and WebGL build of the same application?

$
0
0
See title. Will I run into problems when I want my app to run on Windows and as WebGL at the same time? I want to create rooms in the Windows-Version and join them from the WebGL version.
Usually Windows builds use a different protocol than WebGL, right?

Problems With Photon Animator View in WebGL

$
0
0
Hello!

So, I had a problem using Photon Animator View in a WebGL game. It took me a long while to figure out that it would work without the Photon Animator View, which turned out wasn't really necessary in the end, but still I thought it was worth mentioning.
While I had a Photon Animator View in my player prefab, WebGL would crash while spamming the following message:

InvalidCastException: Unable to cast object of type 'Int32' to type 'Syngle'.

OnPhotonSerializeView - Help needed

$
0
0
Hey guys. So I'm fairly new to Unity, having been using it for about a year. I decided to throw myself in to the world of PUN2 and develop a simple co-op physics platformer as a portfolio piece.

I'm having an issue however when trying to sync a float value across the network. I have two instantiated players with Photon views, and I want the player to set a float value when they are both at the level end goal.

This is my code (shortened) - I can't figure out what I'm doing wrong, so some expert advise would be much appreciated.
public float playerCount;

 public void Start()
{
 playerCount = 0f;
}


 void Update()
    {
        if (PhotonNetwork.IsMasterClient)
        {
            if (playerCount >= GameManager.instance.playersToWin && !GameManager.instance.gameEnded)
            {
                GameManager.instance.gameEnded = true;
                GameManager.instance.photonView.RPC("WinGame", RpcTarget.All);
            }
        }

 void OnTriggerEnter(Collider other)
{
 if (other.CompareTag("LevelEnd"))
        {
                playerCount += 1;
}

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.IsWriting)
        {
            stream.SendNext(playerCount);
        }
        else if (stream.IsReading)
        {
            playerCount = (float)stream.ReceiveNext();
        }
    }

playersToWin float in GameManager is set to 2, with the idea once both players are colliding with the level end collider it'll call the function 'WinGame' as the playerCount will be 2 when synced.

I can see the float value changing in the inspector when the player collides, but only on the local player and not the clone - despite using OnPhotonSerializeView.

Sorry if I sound clueless. I might have jumped in too deep with PUN2, but I'm enjoying every minute of learning from mistakes - this one is giving me a headache though.



Viewing all 8947 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>