- Home /
multiplayer variable synchronization problem
Hello All, I am new to unity multiplayer and i am have a problem getting other player in network i want to get other player and enable or disable other players components or children.
I attached the code and in code i comment the requirments
please let me know if you did not get the answer Advance Thanks For The Help
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class ScoreManager : NetworkBehaviour
{
private static ScoreManager instance;
public static ScoreManager Instance {
get {
return instance;
}
}
[SyncVar]
public int score;
[SyncVar]
public int grass = 1;
[SyncVar]
public bool failed;
[SyncVar]
public bool complete;
public Text MyScoreText;
public Text MyGrassText;
public Text OppenentScoreText;
public Text OppenentGrassText;
public GameObject CompletePanel;
public GameObject FailedPanel;
public GameObject PlayPanel;
void Awake ()
{
instance = this;
}
void Update ()
{
MyGrassText.text = grass.ToString ();
MyScoreText.text = score.ToString ();
//and other player grass text and score text
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "hurdle") {
print ("GameOver....! :P");
failed = true;
//here i want to true other player complete = true;
//and also want to call other player Check();
Check ();
}
if (other.gameObject.tag == "Single") {
print ("Single....! :P");
score += 10 * grass;
}
if (other.gameObject.tag == "Double") {
print ("Double....! :P");
score += 20 * grass;
}
if (other.gameObject.tag == "Grass") {
print ("Grass....! :P");
grass++;
}
}
void Check ()
{
if (complete) {
CompletePanel.SetActive (true);
PlayPanel.SetActive (true);
}
if (failed) {
FailedPanel.SetActive (true);
PlayPanel.SetActive (false);
}
}
}
Answer by x4637x · Oct 30, 2017 at 09:23 AM
You only have this public Text MyScoreText;
in your ScoreManager's instance. And it is not tagged with [SyncVar]
, so I guess what you need is something like a list<string>
to contain all players scores and sync that list between each player.
@x4637x I just want to show other players score. and just want to call other player public function that when trigger tag is hurdle then i can call my check function and also other player function
This tutorial might expand it to you how to do that. Check how she displays different player's name.
thanks for your considerations stay blessed have a good day