From d72a53262348b1c4bc5477dbe3298cadab094a5a Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Fri, 25 Nov 2022 12:09:03 +0800 Subject: [PATCH] Added object checks in leaf scripts --- Assets/Scenes/MainGame.shade | 10 +--------- .../AIBehaviour/Implemented/LeafNodes/LeafAttack.cs | 10 ++++++++-- .../AIBehaviour/Implemented/LeafNodes/LeafPatrol.cs | 8 +++++++- Assets/Scripts/SC_MainMenu.cs | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 39738932..718c2f03 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -8676,15 +8676,7 @@ Scripts: - Type: Homeowner1 Enabled: true - player: 2 - waypoints: - - [2.70000005, 0, -2] - - [-0.300000012, 0, -2.70000005] - - [-2, 0, -3.79999995] - - [-4, 0, -2.0999999] - - [-2.9000001, 0, 2.4000001] - - [-1, 0, 4] - - [2.70000005, 0, 4] + waypointsPool: 51000 patrolSpeed: 1 chaseSpeed: 2 turningSpeed: 5 diff --git a/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafAttack.cs b/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafAttack.cs index e64b63ad..15c0ed67 100644 --- a/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafAttack.cs +++ b/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafAttack.cs @@ -40,8 +40,14 @@ public partial class LeafAttack : BehaviourTreeNode onEnter(BehaviourTreeNodeStatus.RUNNING); - //Succeed when stand in hurt box for long enough - float captureTime = (float)GetNodeData("captureTimeLeft"); + //Succeed when stand in hurt box for long enough + object timeObj = GetNodeData("captureTimeLeft"); + if (timeObj == null) + { + return BehaviourTreeNodeStatus.FAILURE; + } + + float captureTime = (float)GetNodeData("captureTimeLeft"); captureTime -= Time.DeltaTimeF; SetNodeData("captureTimeLeft", captureTime); //Debug.Log(captureTime.ToString()); diff --git a/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafPatrol.cs b/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafPatrol.cs index 248fa8b9..802157cf 100644 --- a/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafPatrol.cs +++ b/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafPatrol.cs @@ -83,7 +83,13 @@ public partial class LeafPatrol : BehaviourTreeNode return; } - waypoints = (List)GetNodeData("waypoints"); + object waypoint = GetNodeData("waypoints"); + if (waypoint == null) + { + return; + } + + waypoints = (List)waypoint; Vector3 targetPosition = waypoints[currentWaypointIndex].GetComponent().GlobalPosition; //Reach waypoint by X and Z being near enough diff --git a/Assets/Scripts/SC_MainMenu.cs b/Assets/Scripts/SC_MainMenu.cs index 0cc5d0dd..05b72ef3 100644 --- a/Assets/Scripts/SC_MainMenu.cs +++ b/Assets/Scripts/SC_MainMenu.cs @@ -12,7 +12,7 @@ public class MainMenu : Script if (Input.GetKey(Input.KeyCode.Space)) { Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); - SceneManager.ChangeScene(86098106); + SceneManager.ChangeScene(89830755); Audio.StopAllSounds(); }