Search Unity

UI Display not correctly one both client

Discussion in 'Multiplayer' started by shuskry, Apr 4, 2017.

  1. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    462
    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!! :p



    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<PhotonView>();
    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();
    }
    }


    }
     
  2. mobileuidev

    mobileuidev

    Joined:
    Apr 4, 2017
    Posts:
    1
    Hi,

    I am also facing issue with mobile UI Display earlier. But it has been resolved now.
     
  3. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    462
    NO publicity please...