Added ItemStash Script for Enemy Pickup
This commit is contained in:
parent
eea58ac447
commit
24b04cb208
29
Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs
Normal file
29
Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs
Normal 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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs.meta
generated
Normal file
11
Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs.meta
generated
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bba26da02d9d0b540be9dee579836806
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -19,7 +19,7 @@ public class TimedSelfDestructWithTimerOrShootToReturn : MonoBehaviour
|
||||
if (timeToDestruction > 0)
|
||||
{
|
||||
timeToDestruction -= Time.deltaTime;
|
||||
GetComponentInChildren<TextMesh>().text = Mathf.Abs(timeToDestruction).ToString();
|
||||
GetComponentInChildren<TextMesh>().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<HealthSystemAttribute>();
|
||||
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<ItemStash>().AddDroppedItemAmountByOne();
|
||||
Destroy(other);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user