change: ownership can now be be changed on objects

This commit is contained in:
Chris
2025-10-08 22:58:39 -04:00
parent 507a735253
commit 0240f677c4
2 changed files with 14 additions and 26 deletions

View File

@@ -32,6 +32,10 @@ namespace Reset.Units{
}
public void TakeDamage(DamageSource source){
if (UnitIsNetworked()) {
TakeOwnershipRpc((source.source as GameObject).GetComponent<NetworkObject>().OwnerClientId);
}
try {
currentHealth -= source.damageDealt;

View File

@@ -13,28 +13,7 @@ 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<bool> 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,8 +33,12 @@ namespace Reset.Units{
if (GetComponent<IKillable>() != null) {
GetComponent<IKillable>().DrawHealthDebug();
}
UnitUpdate();
}
public virtual void UnitUpdate(){ }
void UpdateGizmos(){
string onlineStatus = "Not Online";
Color onlineColor = Color.gray;
@@ -73,8 +56,9 @@ namespace Reset.Units{
Draw.ingame.Label2D(transform.position + Vector3.up * 2.5f, onlineStatus, onlineColor);
}
protected override void OnNetworkPostSpawn(){
// GetComponent<LockOnManager>().AttachCamera(gameObject);
[Rpc(SendTo.Owner)]
public void TakeOwnershipRpc(ulong clientID){
GetComponent<NetworkObject>().ChangeOwnership(clientID);
}
}
}