From 0240f677c44e034b30e0b0d1f819bdbe6ef92f15 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 8 Oct 2025 22:58:39 -0400 Subject: [PATCH] change: ownership can now be be changed on objects --- Assets/Scripts/Units/Enemy.cs | 4 ++++ Assets/Scripts/Units/Unit.cs | 36 ++++++++++------------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/Assets/Scripts/Units/Enemy.cs b/Assets/Scripts/Units/Enemy.cs index a18c5b1..78ff254 100644 --- a/Assets/Scripts/Units/Enemy.cs +++ b/Assets/Scripts/Units/Enemy.cs @@ -32,6 +32,10 @@ namespace Reset.Units{ } public void TakeDamage(DamageSource source){ + if (UnitIsNetworked()) { + TakeOwnershipRpc((source.source as GameObject).GetComponent().OwnerClientId); + } + try { currentHealth -= source.damageDealt; diff --git a/Assets/Scripts/Units/Unit.cs b/Assets/Scripts/Units/Unit.cs index 611a0d7..2d169ea 100644 --- a/Assets/Scripts/Units/Unit.cs +++ b/Assets/Scripts/Units/Unit.cs @@ -13,29 +13,8 @@ namespace Reset.Units{ UnitStart(); } - public virtual async void UnitStart(){ - try { - var netWaitResult = await WaitForNetwork(); - - if (netWaitResult) { - - } - - // OnlineStart(); - Debug.Log("Done"); - } catch { - throw; - } - } - - public async Task WaitForNetwork(){ - while (!NetworkManager.Singleton.IsConnectedClient) { - await Awaitable.NextFrameAsync(); - } - - return (NetworkManager.Singleton.IsConnectedClient); - } - + public virtual void UnitStart(){ } + public bool UnitIsNetworked(){ return NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsHost; } @@ -54,7 +33,11 @@ namespace Reset.Units{ if (GetComponent() != null) { GetComponent().DrawHealthDebug(); } + + UnitUpdate(); } + + public virtual void UnitUpdate(){ } void UpdateGizmos(){ string onlineStatus = "Not Online"; @@ -72,9 +55,10 @@ namespace Reset.Units{ Draw.ingame.Label2D(transform.position + Vector3.up * 2.5f, onlineStatus, onlineColor); } - - protected override void OnNetworkPostSpawn(){ - // GetComponent().AttachCamera(gameObject); + + [Rpc(SendTo.Owner)] + public void TakeOwnershipRpc(ulong clientID){ + GetComponent().ChangeOwnership(clientID); } } } \ No newline at end of file