Я хочу сделать игроку шкалу здоровья. Она спавнится, но не уменьшается, использую Mirror.
using UnityEngine;
using UnityEngine.UI;
using Mirror;
public class Player : NetworkBehaviour
{
private Rigidbody2D rb;
public float speed;
private Vector2 input;
public GameObject prefabIndicators;
public Image bar;
[SyncVar]public float fill;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
CmdSpawn();
fill = 1f;
}
private void Update()
{
if(!isLocalPlayer) return;
input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
bar.fillAmount = fill;
fill -= Time.deltaTime * 0.1f;
}
private void FixedUpdate()
{
rb.MovePosition(rb.position + input * speed / 100);
}
[Command]
private void CmdSpawn()
{
GameObject prefab = Instantiate(prefabIndicators, transform.position, Quaternion.identity);
NetworkServer.Spawn(prefab);
}
}