How would I initiate/change a local UI Text (or any) Element with a value from a Network-Instantiated prefab?
My basic setup is as follows, without any effect:
Scene:
- Camera
- UiElement
Connection is established using MasterServer (Unity) - participants and visual effects are cloned from prefabs like so:
Network.Instantiate(playerPrefab, new Vector3(... etc.
state synchronization works properly as well.
The UI element has the following script attached to identify the value source:
public GameObject Player; //this is the player prefab
public Text energyDisplay; //this is the Text field inside the
void FixedUpdate () {
if(Player.GetComponent<NetworkView>().isMine){
energyDisplay.text = Player.GetComponent<PlayerStats>().energy.ToString();
}
}
Debug of “energyDisplay.text” as well as " Player.GetComponent().energy.ToString();" shows the correct value - however the text field does not change…
I also tried to instantiate a copy of the UI for each individual participant - check ownership and populate, but the result was just the same as above.
What am I doing wrong?