#Dealing Damage to Player

1 messages · Page 1 of 1 (latest)

austere laurel
#

You can make you DealDamage function a ServerRpc and it should work. Post your code here

viscid shadow
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;

public class PlayerHealth : NetworkBehaviour
{
    NetworkVariable<int> health = new NetworkVariable<int>(100, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
    
    void Update()
    {
        if(!IsOwner) return;
        Debug.Log(OwnerClientId + " health: " + health.Value);
    }

    public int GetHealth()
    {
        return health.Value;
    }

    public void DealDamage(int damage)
    {
        if(!IsOwner) return;
        health.Value -= damage;
    }
}

#

thats my deal damage code

#
else if(isMoving && chosenSkill == "Missile")
        {
            for(int i = 0; i<tiles.Length; i++)
            {
                if(tiles[i].isSelectedMissile)
                {
                    StartCoroutine(SpawnAndDespawn(i));
                    GameObject playerOnTile = CheckIfPlayerOnTile(i);

                    if(playerOnTile != null)
                    {
                        playerOnTile.GetComponent<PlayerHealth>().DealDamage(10);
                    }

                    tiles[i].isSelectedMissile = false;
                    isMoving = false;
                    ReturnTileColorToNormal();
                    chosenSkill = "";
                    break;
                }
            }
        }
#

and thats where im placing deal damage

#

thanks so much man im so stressed out trying to work this out

austere laurel
viscid shadow
#

do i need to use RequireOwnership = false?

#

im gonna need to go to school first and im gonna try to work on it again when i get back

austere laurel
#

as long as Player Health is on the player it will be fine

viscid shadow
#

because i did try turning it into a server rpc before

#

it still didnt work