Get a int number from other player on PhotonNetwork
Hello, I'm using PhotonNetwork but I'm starting on the plugin, I done a simple scene, when players join on a room and enter on the scene, he can click on an box, and a variable int will count how much clicks the player done. The problem is that my variable is unique per player, so when I click only the client see, but another players dont see how much clicks the other player done.
Here my script:
 using UnityEngine;
 using System.Collections;
  
 public class ClickToCount : MonoBehaviour
 {
     int clicks;
  
     PhotonView photonView1;
     public void Awake()
  
     {
    
        // PhotonNetwork.automaticallySyncScene = true;
  
     }
     void OnMouseDown ()
     {
         print("foAi");
         if (transform.gameObject.tag == "Player")
         {
             clicks++;
             print("foi");
         }
     }
     void OnGUI()
     {
      
  
         foreach (PhotonPlayer bucetao in PhotonNetwork.playerList)
         {
             GUILayout.Box(bucetao.name + ":" + clicks);
      
         }
     }
  
 }
Here is a print for easy understand, each guest is one player, if I click all players cont 1 click but only for this client (on other player client the count still 0 if he dont click).

Answer by Huntzie · Nov 16, 2015 at 02:30 PM
The issue here is that you are displaying the same local variable alongside the names of each of the players.
From what I can see, you aren't sending any information across the network yet.
I suggest watching this video: https://www.youtube.com/watch?v=mLAilMkRxYU
This should let you know how to send and receive data.
I watched the two next videos, but just saw him putting PhotonView, nothing of code or anything else that could help me, I know taht I need to use PhotonView, but I dont found anything useful to me on the video. I just want to get a int to another player, but I dont found that.
Answer by Fred_Vicentin · Nov 16, 2015 at 05:51 PM
That was my last try, but info and stream are aways null
 using UnityEngine;
 using System.Collections;
 
 public class ClickToCount : MonoBehaviour
 {
     int clicks;
     int todosClicks;
     PhotonView photonView1;
     public PhotonMessageInfo info;
     public PhotonStream stream;
     public void Awake()
     {
 
          PhotonNetwork.automaticallySyncScene = true;
         print(info);
               print(stream);
     }
   
     void OnMouseDown()
     {
         if (transform.gameObject.tag == "Player")
         {
 
             clicks++;
        
         }
     }
    
 
     public void OnPhotonSerializeView()
     {
         if (stream.isWriting)
         {
             stream.SendNext((int)clicks);
         }
 
         else
         {
             this.clicks = (int)stream.ReceiveNext();
             
         }
     }
     void OnGUI()
     {
 
 
         foreach (PhotonPlayer bucetao in PhotonNetwork.playerList)
         {
             GUILayout.Box(bucetao.name + ":" + info);
             
 
         }
     }
 
 
 
 }
 
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                