#Dealing Damage to Player
1 messages · Page 1 of 1 (latest)
You can make you DealDamage function a ServerRpc and it should work. Post your code here
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
Read up here to make DealDamage() into a server RPC
https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/message-system/serverrpc
Introduction
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
as long as Player Health is on the player it will be fine