#Host player does not sync health bar, only the client

2 messages · Page 1 of 1 (latest)

hasty pawn
#

So this is part of the player health script, for some reason when I am hosting the match acting as server+client, when I join as a client using parrelsync. the health of the host goes to 100 and does not sync when is being attacked by the AI, however with the parrelsync client everything works normal though. What could be the issue? Thanks in advance.

#

    void Update()
    {
        if (isLocalPlayer)
        {
            if (damaged)
            {
                damageImage.color = flashColour;
            }
            else
            {
                damageImage.color = Color.Lerp(damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
            }
        }

        timer += Time.deltaTime;
        damaged = false;
    }

    void OnCurrentHealthChanged(int oldValue, int newValue)
    {

        playerHealthText.text = newValue.ToString();
        healthSlider.value = newValue;
    }

    void OnDamagedChanged(bool oldValue, bool newValue)
    {
        if (newValue)
        {
            StartCoroutine("IsHit");
        }
    }

    public void TakeDamage(int amount)
    {
        RpcTakeDamage(amount);
    }

    [ClientRpc]
    public void RpcTakeDamage(int amount)
    {
        if (isLocalPlayer)
        {
            if (timer < invulnerabilityTime)
            {
                return;
            }

            StopCoroutine("IsHit");
            StartCoroutine("IsHit");

            damaged = true;
            currentHealth -= amount;
            int health = Mathf.Max(currentHealth, 0);
            playerHealthText.text = health.ToString();

            if (currentHealth > startingHealth)
            {
                currentHealth = startingHealth;
            }

            healthSlider.value = currentHealth;
            healthFillImage.color = maxHealthColor;
            if (currentHealth <= startingHealth * 0.3)
                healthFillImage.color = minHealthColor;

            timer = 0;
            playerAudio.Play();

            if (currentHealth <= 0 && !isDead)
            {
                Death();
            }
        }