Hello everybody! ( Sorry for my bad english)
First, i specific that i use Photon network to my project
I try to display a simple UI (health and Current level ) but nothing happen like i want…
I use text to display health and it work perfectly on both client
i do the EXACTLY same thing to display the current level but nothing happen… Text is not update …
I drag both of text element ect… i do all the same …
It make me crazy …
So if someone can explain why it’s happening i really appreciate! Thx a lot!! ![]()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerStats : MonoBehaviour
{
PhotonView _view;
public Text healthText; // IT WORK
public int playerHealth;
public int currentPlayerHealth;
public GameObject checkpoint;
public Vector2 checkpointPosition;
public Text exprText; // Don’t work
public int currentLevel;
public int currentExp;
public int[ ] toLevelUp;
// Use this for initialization
void Start()
{
_view = GetComponent();
currentPlayerHealth = playerHealth;
checkpointPosition = checkpoint.transform.position;
SetHealthText();
SetExprText();
}
// Update is called once per frame
void Update()
{
SetExprText();
}
public void addExperience(int experienceToAdd)
{
SetExprText();
currentExp += experienceToAdd;
if (currentExp >= toLevelUp[currentLevel])
{
currentLevel++;
}
SetExprText();
}
public void TakeDamage(int amt)
{
currentPlayerHealth -= amt;
SetHealthText();
if (currentPlayerHealth <= 0)
{
transform.position = checkpointPosition;
currentPlayerHealth = playerHealth;
SetHealthText();
}
}
void SetExprText() // Don’t WORK
{
if (_view.isMine)
{
exprText.text = "Level : " + currentLevel.ToString();
}
}
void SetHealthText()// WORK
{
if (_view.isMine)
{
healthText.text = "Health: " + currentPlayerHealth.ToString();
}
}
}