From 24b04cb2085c9b8bbf1585ca9221bccc5204def1 Mon Sep 17 00:00:00 2001 From: Philip White Date: Mon, 1 Nov 2021 21:04:16 +0000 Subject: [PATCH] Added ItemStash Script for Enemy Pickup --- .../Assets/Scripts/Gameplay/ItemStash.cs | 29 +++++++++++++++++++ .../Assets/Scripts/Gameplay/ItemStash.cs.meta | 11 +++++++ ...medSelfDestructWithTimerOrShootToReturn.cs | 19 +++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs create mode 100644 Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs.meta diff --git a/Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs b/Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs new file mode 100644 index 0000000..63e7281 --- /dev/null +++ b/Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ItemStash : MonoBehaviour +{ + [Header("Dropped Item Amount")] + public int droppedItemAmount = 3; + + private void OnTriggerEnter2D(Collider2D other) + { + string objectTag = other.gameObject.tag; + if (objectTag == "Enemy" && droppedItemAmount > 0) + { + droppedItemAmount -= 1; + other.gameObject.GetComponent().hasDroppableObject = true; + } + } + + public void AddDroppedItemAmountByOne() + { + droppedItemAmount += 1; + } + + private void Update() + { + + } +} diff --git a/Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs.meta b/Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs.meta new file mode 100644 index 0000000..ef2074a --- /dev/null +++ b/Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bba26da02d9d0b540be9dee579836806 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimerOrShootToReturn.cs b/Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimerOrShootToReturn.cs index f962066..a2dbfa2 100644 --- a/Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimerOrShootToReturn.cs +++ b/Unity-Files/Assets/Scripts/Gameplay/TimedSelfDestructWithTimerOrShootToReturn.cs @@ -19,7 +19,7 @@ public class TimedSelfDestructWithTimerOrShootToReturn : MonoBehaviour if (timeToDestruction > 0) { timeToDestruction -= Time.deltaTime; - GetComponentInChildren().text = Mathf.Abs(timeToDestruction).ToString(); + GetComponentInChildren().text = timeToDestruction.ToString().Split('.')[0]; } else { @@ -30,8 +30,25 @@ public class TimedSelfDestructWithTimerOrShootToReturn : MonoBehaviour // This function will destroy this object :( void DestroyMe() { + HealthSystemAttribute healthScript = GameObject.Find("CollisionDetector").gameObject.GetComponent(); + if (healthScript != null) + { + // subtract health from the player + healthScript.ModifyHealth(-1); + } Destroy(gameObject); // Bye bye! } + + private void OnTriggerEnter2D(Collider2D other) + { + string objectTag = other.gameObject.tag; + if (objectTag == "Bullet") + { + GameObject.Find("CollisionDetector").GetComponent().AddDroppedItemAmountByOne(); + Destroy(other); + Destroy(gameObject); + } + } }