#pragma warning disable
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityEngine;
using System.Collections;
public class valuesControlNet : NetworkBehaviour
{
public Image bar;
public Text name;
public string nameStr;
public GameObject canvas;
public float health;
public float max;
public int strikePower;
public menuOfButtons ok;
void Start()
{
ok = GameObject.FindObjectOfType<menuOfButtons>();
if (isLocalPlayer)
canvas.SetActive(false);
else
canvas.SetActive(true);
}
[Command]
void CmdSendHealth(string _playerName, float _health, string _nameFORsend, float _maxH, int _power)
{
StartCoroutine(Sended(_playerName, _health, _nameFORsend, _maxH, _power));
}
[ClientRpc]
void RpcSENDhealth(string _playerName, float _health, string _nameFORsend, float _maxH, int _power)
{
StartCoroutine(Sended(_playerName, _health, _nameFORsend, _maxH, _power));
}
IEnumerator Sended(string _playerName, float _health, string _nameFORsend, float _maxH, int _power)
{
yield return new WaitForSeconds(0.15f);
valuesControlNet main = GameObject.Find(_playerName).GetComponent<valuesControlNet>();
main.nameStr = _nameFORsend;
main.health = _health;
main.max = _maxH;
main.strikePower = _power;
}
void Update()
{
if (isLocalPlayer)
{
if (ok.isHost && !ok.isClient && GetComponent<setup>().playerConnected)
RpcSENDhealth(transform.name, health, nameStr, max, strikePower);
if (ok.isClient && !ok.isHost)
CmdSendHealth(transform.name, health, nameStr, max, strikePower);
return;
}
float convertHealth = health / max;
bar.fillAmount = convertHealth;
name.text = nameStr;
}
}