Fixed Persisting of Objects Past Game (COMPLETED)

This commit is contained in:
2022-04-17 00:58:55 -05:00
parent 578e4aa69d
commit 522ff7ceb2
9 changed files with 224 additions and 91 deletions

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MLAPI;
using MLAPI.Messaging;
public class ObjectCleanup : NetworkBehaviour {
void Start() {
DontDestroyOnLoad(gameObject);
}
[ServerRpc(RequireOwnership = false)]
public void DestroyPersistingNetObjectsServerRPC() {
NetworkObject[] networkObjects = FindObjectsOfType<NetworkObject>();
Debug.Log("Here");
foreach (NetworkObject nObj in networkObjects) {
GameObject netObj = nObj.gameObject;
if (netObj == gameObject) { continue; }
netObj.GetComponent<NetworkObject>().Despawn(true);
}
}
}