From 9a0cc011c72312dc3ad0de9de1c5e00684f72a10 Mon Sep 17 00:00:00 2001 From: Yvo02 <115483377+Yvo02@users.noreply.github.com> Date: Wed, 26 Oct 2022 14:31:16 +0200 Subject: [PATCH] #479 Apply suggestions from code review Co-authored-by: Falko <10247603+falko17@users.noreply.github.com> --- Assets/SEE/Game/GameNodeMarker.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Assets/SEE/Game/GameNodeMarker.cs b/Assets/SEE/Game/GameNodeMarker.cs index 2573e2e2ea..dca931a9be 100644 --- a/Assets/SEE/Game/GameNodeMarker.cs +++ b/Assets/SEE/Game/GameNodeMarker.cs @@ -22,14 +22,14 @@ public static class GameNodeMarker /// the position in world space for the center point of the new marker /// the scale in world space of the new marker /// new marker game object or null if none could be created or a marker already exists - /// + /// If is null. public static GameObject addSphere(GameObject parent, Vector3 position, Vector3 worldSpaceScale) { GameObject sphere; if(parent == null) { - throw new Exception("GameObject must not be null."); + throw new ArgumentNullException(nameof(parent)); } else if (deleteExistingSphere(parent)) { @@ -48,21 +48,20 @@ public static GameObject addSphere(GameObject parent, Vector3 position, Vector3 } /// - /// This function searches all children of for existing childs with the name + /// This function searches all children of for existing children with the name /// "Sphere". If a sphere marker is already present it will be destroyed. /// /// the game object to be checked for existing sphere marker /// true if marker exists private static bool deleteExistingSphere(GameObject parent) { - for (int i = 0; i <= parent.transform.childCount - 1; i++) + foreach (Transform child in parent.transform) { - if (parent.transform.GetChild(i).transform.name == "Sphere" && parent.transform.childCount > 0) + if (child.name == "Sphere") { - GameObject sphere = parent.transform.GetChild(i).gameObject; //FIXME: network operation for deleting an existing marker not working properly //new DeleteNetAction(sphere.name).Execute(); - Destroyer.DestroyGameObject(parent.transform.GetChild(i).gameObject); + Destroyer.DestroyGameObject(child.gameObject); return true; } }