From 5339e773f247bdf81fa3b30a4a03c748732b5046 Mon Sep 17 00:00:00 2001 From: Neil Kollack Date: Sat, 16 Apr 2022 16:33:55 -0500 Subject: fix: feedback(easier trap section + better damage) --- Assets/Scripts/LevelController.cs | 46 ++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'Assets/Scripts/LevelController.cs') diff --git a/Assets/Scripts/LevelController.cs b/Assets/Scripts/LevelController.cs index 7c7355e..1b8bd47 100644 --- a/Assets/Scripts/LevelController.cs +++ b/Assets/Scripts/LevelController.cs @@ -1,12 +1,15 @@ using System.Collections; using System.Collections.Generic; +using UnityEditor; using UnityEngine; using UnityEngine.SceneManagement; public class LevelController : MonoBehaviour { [SerializeField] GameObject treasure; - // Start is called before the first frame update + [SerializeField] List enemies; + + private string clone = "(Clone)"; public void StartGame() { @@ -15,13 +18,44 @@ public class LevelController : MonoBehaviour public void ResetLevel() { + //Destroy Destroy(GameObject.Find("Boulder(Clone)")); Destroy(GameObject.Find("BoobyTrapSpawnPoint(Clone)")); - var currentTreasure = GameObject.Find("Treasure"); - if(currentTreasure) - Destroy(currentTreasure); - else - Destroy(GameObject.Find("Treasure(Clone)")); + CloneDestroy("Treasure"); + DestroyList(enemies); + + //Instantiate Instantiate(treasure); + InstantiateList(enemies); + } + + private void CloneDestroy(string objectName) + { + var obj = GameObject.Find(objectName); + if (obj) + Destroy(obj); + else + { + obj = GameObject.Find(objectName + clone); + if (obj) + Destroy(GameObject.Find(objectName + clone)); + } + } + + private void DestroyList(List gameObjects) + { + foreach(GameObject obj in gameObjects) + { + CloneDestroy(obj.name); + } + } + + private void InstantiateList(List gameObjects) + { + foreach (GameObject obj in gameObjects) + { + PrefabUtility.RevertPrefabInstance(obj, InteractionMode.AutomatedAction); + Instantiate(obj); + } } } -- cgit v1.2.3-70-g09d2