diff --git a/Assets/Scripts/Enemy/EnemyHealth.cs b/Assets/Scripts/Enemy/EnemyHealth.cs index 9b80f3873d16935432382c0cd27a4748c8714560..69203dca4f0f950a15d02ce28db625ccc6ac13af 100644 --- a/Assets/Scripts/Enemy/EnemyHealth.cs +++ b/Assets/Scripts/Enemy/EnemyHealth.cs @@ -39,6 +39,11 @@ public class EnemyHealth : MonoBehaviour void Update() { + if (isSinking && startingHealth > 0) + { + // memindahkan object ke bawah + isSinking = false; + } if (isSinking) { // memindahkan object ke bawah @@ -104,6 +109,14 @@ public class EnemyHealth : MonoBehaviour GetComponent<Rigidbody>().isKinematic = true; isSinking = true; ScoreManager.score += scoreValue; - Destroy(gameObject, 2f); + + if (gameObject.GetComponent<RangedEnemyAttack>() != null) + { + startingHealth = 100; + gameObject.SetActive(false); + } else + { + Destroy(gameObject, 2f); + } } } diff --git a/Assets/Scripts/MainMenu/MainMenu.cs b/Assets/Scripts/MainMenu/MainMenu.cs index 51496580d2140b334e833b2c8d5f24bb3e8623e9..2bc890294c919ba2ff5d211234481790d79bb1e3 100644 --- a/Assets/Scripts/MainMenu/MainMenu.cs +++ b/Assets/Scripts/MainMenu/MainMenu.cs @@ -12,14 +12,20 @@ public class MainMenu : MonoBehaviour { //SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex+1); playerName = GameObject.Find("Text").GetComponent<Text>().text; - Debug.Log(GameObject.Find("Text").GetComponent<Text>().text); + if (playerName == "") + { + playerName = "<Anonymous>"; + } SceneManager.LoadScene("WaveComplete"); } public void PlayZenMode() { //SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); playerName = GameObject.Find("Text").GetComponent<Text>().text; - Debug.Log(GameObject.Find("Text").GetComponent<Text>().text); + if (playerName == "") + { + playerName = "<Anonymous>"; + } SceneManager.LoadScene("ZenComplete"); } public void QuitGame() diff --git a/Assets/Scripts/Managers/WaveManager.cs b/Assets/Scripts/Managers/WaveManager.cs index 4844ec2224c57dbcb94bc8b9d63539d8f8f6fe25..9d8e82884de0661e43f9cacbd79344fb29755696 100644 --- a/Assets/Scripts/Managers/WaveManager.cs +++ b/Assets/Scripts/Managers/WaveManager.cs @@ -47,6 +47,16 @@ public class WaveManager : MonoBehaviour Vector3 position = new Vector3(Random.Range(-10.0F, 10.0F), 1, Random.Range(-10.0F, 10.0F)); Instantiate (Factory.FactoryMethod(0), position, Quaternion.identity); + + // Object Pooling + + GameObject skeleton = ObjectPool.SharedInstance.GetPooledObject(); + if (skeleton != null) + { + skeleton.transform.position = position; + skeleton.transform.rotation = Quaternion.identity; + skeleton.SetActive(true); + } } void SpawnBomber() diff --git a/Assets/Scripts/ObjectPooling.meta b/Assets/Scripts/ObjectPooling.meta new file mode 100644 index 0000000000000000000000000000000000000000..fb0e76843e08fed389f58037760d82c0129b5059 --- /dev/null +++ b/Assets/Scripts/ObjectPooling.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1832cfdaaf499294db4240a22f22069c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/ObjectPooling/ObjectPool.cs b/Assets/Scripts/ObjectPooling/ObjectPool.cs new file mode 100644 index 0000000000000000000000000000000000000000..5a92c4d53cc91356aa8d548b4277c07d52b856d7 --- /dev/null +++ b/Assets/Scripts/ObjectPooling/ObjectPool.cs @@ -0,0 +1,41 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ObjectPool : MonoBehaviour +{ + public static ObjectPool SharedInstance; + public List<GameObject> pooledObjects; + public GameObject objectToPool; + public int amountToPool; + + private void Awake() + { + SharedInstance = this; + } + + private void Start() + { + pooledObjects = new List<GameObject>(); + GameObject tmp; + for(int i = 0; i < amountToPool; i++) + { + tmp = Instantiate(objectToPool); + tmp.SetActive(false); + pooledObjects.Add(tmp); + } + } + + public GameObject GetPooledObject() + { + for(int i = 0; i < amountToPool; i++) + { + if (!pooledObjects[i].activeInHierarchy) + { + return pooledObjects[i]; + } + } + + return null; + } +} diff --git a/Assets/Scripts/ObjectPooling/ObjectPool.cs.meta b/Assets/Scripts/ObjectPooling/ObjectPool.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..47f5d7a4c80b2c9036693a0c4a264e666382c59f --- /dev/null +++ b/Assets/Scripts/ObjectPooling/ObjectPool.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b7784cea58a4d584281884f8a12e7671 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index f6121836f78449b3b59f27bb2db1003594043e71..fb0e5a4b518d4bcabdc6ccc3f39465c2631b53f2 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -30,10 +30,10 @@ EditorUserSettings: value: 22424703114646680e0b0227036c6515183417273c2423242867083debf42d flags: 0 RecentlyUsedScenePath-8: - value: 22424703114646680e0b0227036c681100123b2521382a35392c5326ece92021 + value: 22424703114646680e0b0227036c72111f19352f223d68252320092a flags: 0 RecentlyUsedScenePath-9: - value: 22424703114646680e0b0227036c72111f19352f223d68252320092a + value: 22424703114646680e0b0227036c681100123b2521382a35392c5326ece92021 flags: 0 vcSharedLogLevel: value: 0d5e400f0650