mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-24 19:34:38 -05:00
Fixed Persisting of Objects Past Game (COMPLETED)
This commit is contained in:
25
Assets/Scripts/Network/ObjectCleanup.cs
Normal file
25
Assets/Scripts/Network/ObjectCleanup.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user