From 99fe74a8d96012e8058fa7fcbf2dfe5d488f0b68 Mon Sep 17 00:00:00 2001 From: Julia Butenhoff Date: Wed, 30 Mar 2022 13:27:01 -0500 Subject: [PATCH] Fixed King Null Ref Errors - Fixed KingPlace and KingMove Null Refs - Changed the Networked Slime to isTrigger instead of solid --- Assets/Prefabs/King/KingGrid.prefab | 2 +- Assets/Prefabs/King/Slime.prefab | 2 +- Assets/Scripts/KingScripts/Goo.cs | 4 +++- Assets/Scripts/KingScripts/GridReveal.cs | 5 +++++ Assets/Scripts/KingScripts/KingMove.cs | 9 ++++++--- Assets/Scripts/KingScripts/KingPlace.cs | 19 +++++++++++++++---- Assets/Scripts/Network/Game/GameHandler.cs | 2 +- ProjectSettings/TagManager.asset | 1 + UserSettings/EditorUserSettings.asset | 10 +++++----- 9 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Assets/Prefabs/King/KingGrid.prefab b/Assets/Prefabs/King/KingGrid.prefab index 44fd0d1..6f771af 100644 --- a/Assets/Prefabs/King/KingGrid.prefab +++ b/Assets/Prefabs/King/KingGrid.prefab @@ -407410,7 +407410,7 @@ GameObject: - component: {fileID: 7860323274346430103} m_Layer: 8 m_Name: MountainGrid - m_TagString: Untagged + m_TagString: MountainGrid m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 diff --git a/Assets/Prefabs/King/Slime.prefab b/Assets/Prefabs/King/Slime.prefab index cbb3016..fa32414 100644 --- a/Assets/Prefabs/King/Slime.prefab +++ b/Assets/Prefabs/King/Slime.prefab @@ -195,7 +195,7 @@ BoxCollider: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2350198489747510937} m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_Enabled: 1 serializedVersion: 2 m_Size: {x: 0.12903199, y: 0.12903199, z: 0.12903199} diff --git a/Assets/Scripts/KingScripts/Goo.cs b/Assets/Scripts/KingScripts/Goo.cs index 8f7c0ad..0ea811c 100644 --- a/Assets/Scripts/KingScripts/Goo.cs +++ b/Assets/Scripts/KingScripts/Goo.cs @@ -11,7 +11,9 @@ public class Goo : MonoBehaviour void FixedUpdate() { Lifetime++; if(Lifetime == 850) { - DespawnMyselfServerRPC(); + if (NetworkManager.Singleton.IsServer) { + DespawnMyselfServerRPC(); + } } } diff --git a/Assets/Scripts/KingScripts/GridReveal.cs b/Assets/Scripts/KingScripts/GridReveal.cs index 2d4bf11..411eecd 100644 --- a/Assets/Scripts/KingScripts/GridReveal.cs +++ b/Assets/Scripts/KingScripts/GridReveal.cs @@ -22,6 +22,11 @@ public class GridReveal : MonoBehaviour for (int i = Rows.Length-1; i > ROSCount-1; i--) {// Disables most of the Rows that the King can't see Rows[i].SetActive(false); } + ToggleMountainGrid(true); + } + + public void ToggleMountainGrid(bool state) { + Rows[Rows.Length - 2].SetActive(state); } public void GridSwitch(bool State) {//Activates or deactivates the Grid diff --git a/Assets/Scripts/KingScripts/KingMove.cs b/Assets/Scripts/KingScripts/KingMove.cs index 1fe548a..f5546c9 100644 --- a/Assets/Scripts/KingScripts/KingMove.cs +++ b/Assets/Scripts/KingScripts/KingMove.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using MLAPI; +using UnityEngine.SceneManagement; public class KingMove : NetworkBehaviour { @@ -20,10 +21,12 @@ public class KingMove : NetworkBehaviour transform.position = KingStrPos; } - void Start() - { + void Start() { // Turn on the king grid after a couple seconds. Allows scripts to grab their reference to it before it is disabled - StartCoroutine(TurnOffGridAtStartOfMatch()); + // Only try to grab references if we are actually in the game scene + if (SceneManager.GetActiveScene().buildIndex == 3) { + StartCoroutine(TurnOffGridAtStartOfMatch()); + } } IEnumerator TurnOffGridAtStartOfMatch() diff --git a/Assets/Scripts/KingScripts/KingPlace.cs b/Assets/Scripts/KingScripts/KingPlace.cs index d23b0f9..59350a7 100644 --- a/Assets/Scripts/KingScripts/KingPlace.cs +++ b/Assets/Scripts/KingScripts/KingPlace.cs @@ -1,8 +1,10 @@ +using System; using System.Collections; using System.Collections.Generic; using MLAPI; using MLAPI.Messaging; using UnityEngine; +using UnityEngine.SceneManagement; public class KingPlace : NetworkBehaviour { @@ -54,10 +56,19 @@ public class KingPlace : NetworkBehaviour private GameObject placedObj; - void Awake() - { - Grid = GameObject.FindGameObjectWithTag("KingGrid"); - MountGrid = Grid.transform.Find("MountainGrid").gameObject; + void Start() { + // Only try to grab references if we are actually in the game scene + if (SceneManager.GetActiveScene().buildIndex == 3) { + Grid = GameObject.FindGameObjectWithTag("KingGrid"); + MountGrid = GameObject.FindGameObjectWithTag("MountainGrid"); + try + { + Grid.GetComponent().ToggleMountainGrid(false); + } catch(NullReferenceException e) + { + Debug.LogError(e); + } + } } bool Avaliable; diff --git a/Assets/Scripts/Network/Game/GameHandler.cs b/Assets/Scripts/Network/Game/GameHandler.cs index 5d32cdb..23f7c40 100644 --- a/Assets/Scripts/Network/Game/GameHandler.cs +++ b/Assets/Scripts/Network/Game/GameHandler.cs @@ -101,7 +101,7 @@ public class GameHandler : NetworkBehaviour [ServerRpc] private void SpawnCountdownServerRpc(ServerRpcParams serverRpcParams = default) { _countdownUI = Instantiate(coundownUI, Vector3.zero, Quaternion.identity).gameObject; - _countdownUI.GetComponent().Spawn(); + _countdownUI.GetComponent().Spawn(null, true); } [ServerRpc] diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index e42c8ec..e686ea5 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -27,6 +27,7 @@ TagManager: - FoothillsRespawnPoint - MountainRespawnPoint - PlayerModel + - MountainGrid layers: - Default - TransparentFX diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index fef9aa5..39c518d 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -21,19 +21,19 @@ EditorUserSettings: value: 22424703114646680e0b0227036c731f1415016439262f2434 flags: 0 RecentlyUsedScenePath-5: - value: 22424703114646680e0b0227036c78111b125507233d28242c20137df7ee3d2cfb + value: 22424703114646680e0b0227036c7b151b180b6501273035202c1327d1e33136e7a923e7ee2e26 flags: 0 RecentlyUsedScenePath-6: - value: 22424703114646680e0b0227036c6f02131b172b282d347e38271427fb + value: 22424703114646680e0b0227036c7b151b180b6501273035202c1327d1e33136e7a923e7ee2e26 flags: 0 RecentlyUsedScenePath-7: - value: 22424703114646680e0b0227036c78111b125507233d28242c20137df7ee3d2cfb + value: 22424703114646680e0b0227036c7b151b180b6501273035202c1327d1e33136e7a923e7ee2e26 flags: 0 RecentlyUsedScenePath-8: - value: 22424703114646680e0b0227036c6f02131b172b282d347e38271427fb + value: 22424703114646680e0b0227036c78111b125507233d28242c20137df7ee3d2cfb flags: 0 RecentlyUsedScenePath-9: - value: 22424703114646680e0b0227036c7b151b180b6501273035202c1327d1e33136e7a923e7ee2e26 + value: 22424703114646680e0b0227036c6f02131b172b282d347e38271427fb flags: 0 vcSharedLogLevel: value: 0d5e400f0650