change: ownership can now be be changed on objects
This commit is contained in:
@@ -32,6 +32,10 @@ namespace Reset.Units{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void TakeDamage(DamageSource source){
|
public void TakeDamage(DamageSource source){
|
||||||
|
if (UnitIsNetworked()) {
|
||||||
|
TakeOwnershipRpc((source.source as GameObject).GetComponent<NetworkObject>().OwnerClientId);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
currentHealth -= source.damageDealt;
|
currentHealth -= source.damageDealt;
|
||||||
|
|
||||||
|
|||||||
@@ -13,28 +13,7 @@ namespace Reset.Units{
|
|||||||
UnitStart();
|
UnitStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async void UnitStart(){
|
public virtual 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 bool UnitIsNetworked(){
|
public bool UnitIsNetworked(){
|
||||||
return NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsHost;
|
return NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsHost;
|
||||||
@@ -54,8 +33,12 @@ namespace Reset.Units{
|
|||||||
if (GetComponent<IKillable>() != null) {
|
if (GetComponent<IKillable>() != null) {
|
||||||
GetComponent<IKillable>().DrawHealthDebug();
|
GetComponent<IKillable>().DrawHealthDebug();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UnitUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void UnitUpdate(){ }
|
||||||
|
|
||||||
void UpdateGizmos(){
|
void UpdateGizmos(){
|
||||||
string onlineStatus = "Not Online";
|
string onlineStatus = "Not Online";
|
||||||
Color onlineColor = Color.gray;
|
Color onlineColor = Color.gray;
|
||||||
@@ -73,8 +56,9 @@ namespace Reset.Units{
|
|||||||
Draw.ingame.Label2D(transform.position + Vector3.up * 2.5f, onlineStatus, onlineColor);
|
Draw.ingame.Label2D(transform.position + Vector3.up * 2.5f, onlineStatus, onlineColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnNetworkPostSpawn(){
|
[Rpc(SendTo.Owner)]
|
||||||
// GetComponent<LockOnManager>().AttachCamera(gameObject);
|
public void TakeOwnershipRpc(ulong clientID){
|
||||||
|
GetComponent<NetworkObject>().ChangeOwnership(clientID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user