forked from Serinoxxx/NGOAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkDamageable.cs
60 lines (48 loc) · 1.83 KB
/
NetworkDamageable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
namespace MalbersAnimations.NetCode
{
[RequireComponent(typeof(MDamageable))]
public class NetworkDamageable : NetworkBehaviour
{
MDamageable _damageable;
ServerAuthAnimal _serverAuthAnimal;
private void Start()
{
_damageable = GetComponent<MDamageable>();
_serverAuthAnimal = GetComponent<ServerAuthAnimal>();
}
public void SendDamageToClients(float amount)
{
Debug.Log($"{gameObject.name} received {amount} damage");
//Only host should handle the events
if (!IsServer)
{ return; }
Debug.Log($"Sending {amount} damage to clients");
ReceiveDamageRpc(amount, _damageable.LastDamage.WasCritical, _damageable.HitDirection);
}
[Rpc(SendTo.NotMe)]
void ReceiveDamageRpc(float amount, bool wasCritical, Vector3 direction)
{
Debug.Log($"{gameObject.name} just took {amount} damage!");
_damageable.ReceiveDamage(direction, gameObject, _damageable.stats.stats[0].ID, amount, wasCritical, true, null, false);
}
// public void SendCriticalDamageToClients()
// {
// Debug.Log($"{gameObject.name} received critical damage");
// //Only host should handle the events
// if (!IsServer)
// { return; }
// Debug.Log($"Sending critical damage to clients");
// ReceiveCriticalDamageRpc();
// }
// [Rpc(SendTo.NotMe)]
// void ReceiveCriticalDamageRpc()
// {
// Debug.Log($"{gameObject.name} just took critical damage!");
// _damageable.criticalReaction.TryReact(_serverAuthAnimal);
// }
}
}