Added ItemStash Script for Enemy Pickup

This commit is contained in:
Philip W 2021-11-01 21:04:16 +00:00
parent eea58ac447
commit 24b04cb208
3 changed files with 58 additions and 1 deletions

View File

@ -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<EnemyReturn>().hasDroppableObject = true;
}
}
public void AddDroppedItemAmountByOne()
{
droppedItemAmount += 1;
}
private void Update()
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bba26da02d9d0b540be9dee579836806
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -19,7 +19,7 @@ public class TimedSelfDestructWithTimerOrShootToReturn : MonoBehaviour
if (timeToDestruction > 0) if (timeToDestruction > 0)
{ {
timeToDestruction -= Time.deltaTime; timeToDestruction -= Time.deltaTime;
GetComponentInChildren<TextMesh>().text = Mathf.Abs(timeToDestruction).ToString(); GetComponentInChildren<TextMesh>().text = timeToDestruction.ToString().Split('.')[0];
} }
else else
{ {
@ -30,8 +30,25 @@ public class TimedSelfDestructWithTimerOrShootToReturn : MonoBehaviour
// This function will destroy this object :( // This function will destroy this object :(
void DestroyMe() void DestroyMe()
{ {
HealthSystemAttribute healthScript = GameObject.Find("CollisionDetector").gameObject.GetComponent<HealthSystemAttribute>();
if (healthScript != null)
{
// subtract health from the player
healthScript.ModifyHealth(-1);
}
Destroy(gameObject); Destroy(gameObject);
// Bye bye! // Bye bye!
} }
private void OnTriggerEnter2D(Collider2D other)
{
string objectTag = other.gameObject.tag;
if (objectTag == "Bullet")
{
GameObject.Find("CollisionDetector").GetComponent<ItemStash>().AddDroppedItemAmountByOne();
Destroy(other);
Destroy(gameObject);
}
}
} }