0
\$\begingroup\$

I'm trying make a multiplayer game, using Mirror, but can't get the health indicator to spawn. An error message appears:

Send command attempted while NetworkClient is not ready.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Mirror;

public class IndicatorsPlayer : NetworkBehaviour
{
[SerializeField]
    private GameObject IndicatorsPlayerPrefab;
   
    [SerializeField]
    private Image bar;

    [SerializeField]
    private float fill = 1f;

    void Update ()
    {
        if(this.isLocalPlayer)
        {
            this.CmdSpawnIndicatorsPlayer();
           
        }
    }

    [Command]
    void CmdSpawnIndicatorsPlayer()
    {
    GameObject IndicatorsPlayer = Instantiate(IndicatorsPlayerPrefab, this.transform.position, Quaternion.identity);
            NetworkServer.Spawn(IndicatorsPlayer);
            fill -= Time.deltaTime * 0.1f;
        bar.fillAmount = fill;

    }
}
\$\endgroup\$
3
  • \$\begingroup\$ Did you consider waiting until the network client is ready, by checking NetworkClient.ready? \$\endgroup\$
    – DMGregory
    Nov 6, 2022 at 13:44
  • \$\begingroup\$ yes, Debug.log(object) appears. or did I misunderstand? \$\endgroup\$
    – Iya
    Nov 6, 2022 at 15:33
  • \$\begingroup\$ You have not told me enough to understand what you did and what result you observed. Try editing your question to walk through this in detail. \$\endgroup\$
    – DMGregory
    Nov 6, 2022 at 15:35

0

You must log in to answer this question.

Browse other questions tagged .