I am a begineer photon user. I have a problem by integrating it.
The question is I have a prefab “spinner” with child canvas showing score and it has a player script [code downwards].
when other clients instantiated then the player only can see its own score but other client’s score shows 0 on every player. Help…!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Player : Photon.MonoBehaviour {
Camera playerCam;
Text scoretext;
// Use this for initialization
int score;
int id;
void Awake()
{
score = 0;
id = PhotonNetwork.player.ID;
Debug.Log (id);
// DontDestroyOnLoad (gameObject);
// //playerCam = GetComponentInChildren ();
//
// if (!photonView.isMine) {
//
//// playerCam.gameObject.SetActive (false);
// }
scoretext = GameObject.Find (“Spinner(Clone)/CanvasSpinner/Panel/Score”).GetComponent ();
}
void OnTriggerEnter2D(Collider2D col){
if (col.gameObject.tag == "enemy") {
Debug.Log ("collision");
if (photonView.isMine) {
score += 1;
scoretext.text = score.ToString ();
GetComponent<PhotonView> ().RPC ("UpdateScores", PhotonTargets.All,score);
}
Destroy (col.gameObject);
GetComponent<PhotonView> ().RPC ("UpdateScores", PhotonTargets.All);
}
}
[RPC]
void UpdateScores(int test) {
scoretext.text = test.ToString();
Debug.Log (scoretext.text);
//Keep in mind that it doesn't matter that 'username' and 'score' above are the same as when you send it; they just need to both be the same Type of variable, such as string and float.
//You now have the username and the score on other clients. Do your 'update' stuff here.
}