Merge branch 'DespawnBumpers'

This commit is contained in:
Julia Butenhoff 2022-04-13 13:08:33 -05:00
commit 37f15d10cc
4 changed files with 56 additions and 1 deletions

View File

@ -17,6 +17,18 @@ MonoBehaviour:
PrefabHashGenerator: TempBumper
AlwaysReplicateAsRoot: 0
DontDestroyWithOwner: 0
--- !u!114 &5019352696064972879
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8337410631319514038}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fefb30a560cee67419c8a02555b247b2, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &3409778990194893120
PrefabInstance:
m_ObjectHideFlags: 0

View File

@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MLAPI;
using MLAPI.Messaging;
public class BumperDespawn : NetworkBehaviour {
private float despawnTimer = 20f;
// Start is called before the first frame update
void Start() {
// Only start the despawn timer on the host system
if (!IsHost) { return; }
// Start the Despawn Timer
StartCoroutine(DespawnTimer());
}
IEnumerator DespawnTimer() {
// Wait for the timer to complete
yield return new WaitForSecondsRealtime(despawnTimer);
// Despawn the Bumper this is attached to
DespawnMyselfServerRPC();
}
[ServerRpc(RequireOwnership = false)]
private void DespawnMyselfServerRPC() {
gameObject.GetComponent<NetworkObject>().Despawn(true);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fefb30a560cee67419c8a02555b247b2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -119,7 +119,7 @@ public class GameHandler : NetworkBehaviour
[ServerRpc]
private void DespawnCountdownServerRpc(ServerRpcParams serverRpcParams = default) {
_countdownUI.GetComponent<NetworkObject>().Despawn();
_countdownUI.GetComponent<NetworkObject>().Despawn(true);
Destroy(_countdownUI);
}