UI で playerHealth を作成する必要があります。すべて正常に動作しますが、別のプレイヤーと参加すると UI が表示されません。ローカル プレイヤーの場合、UI ゲームオブジェクトを有効にしようとしましたが、うまくいきません。次のような ID でプレーヤーの負荷値を作成する方法: playerHealth = playerID.health;?
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class PlayerStats : NetworkBehaviour
{
NetworkConfigurator netConf;
[SyncVar]
public float playerHealth;
void Start ()
{
netConf = GameObject.Find ("NetworkManager").GetComponent<NetworkConfigurator> ();
netConf.userStatus.SetActive (isLocalPlayer); // Here the problem
}
void Update ()
{
if (Input.GetKeyDown (KeyCode.LeftBracket))
{
if (playerHealth == 0)
return;
playerHealth -= 5;
}
if (Input.GetKeyDown (KeyCode.RightBracket))
{
if (playerHealth == 100)
return;
playerHealth += 5;
}
netConf.healthAmount.text = "" + playerHealth;
netConf.healthBar.fillAmount = playerHealth / 100;
}
}