Question by
ArmswieldTheHero · Oct 23, 2016 at 03:02 PM ·
photonvaluepunhealth
How to synchronize Photon networked values with text in the GUI
I have my players health synchronizing over photonview, I want these values to go to a Canvas > image > text, but whenever I use standard drag and drop using the prefabs, the referenced script for the health returns null. //Health bar script for player 2 using UnityEngine; using System.Collections; using UnityEngine.UI;
public class HealthBar2 : Photon.MonoBehaviour
{
public HealthPlayer2 health;
public Text valueText;
public float MaxValue { get; set; }
public float value
{
set
{
string[] tmp = valueText.text.Split(':');
valueText.text = tmp[0] + ":" + health.health2.ToString();
}
}
// Use this for initialization
void Start()
{
health = GetComponent<HealthPlayer2>();
}
// Update is called once per frame
void Update()
{
if (health = null)
{
health = GetComponent<HealthPlayer2>();
}
value = health.health2;
}
}
//player 2's health script
using UnityEngine;
using System.Collections;
public class HealthPlayer2 : Photon.MonoBehaviour {
public float health2 = 1000f;
// Use this for initialization
void Start () {
}
public void TakeDamage(float amt)
{
health2 -= amt;
if (health2 <= 0)
{
Die();
}
}
void Die()
{
PhotonNetwork.Destroy(gameObject);
}
}
Comment
Your answer
Follow this Question
Related Questions
Randomize a value through Photon 0 Answers
Player names with photon PUN 1 Answer
PhotonUnity player move object problem ! 1 Answer
Racing game using PUN 2 0 Answers