我需要用 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;
}
}