summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Enemy/EnemyAttackScript.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Enemy/EnemyAttackScript.cs')
-rwxr-xr-xAssets/Scripts/Enemy/EnemyAttackScript.cs50
1 files changed, 50 insertions, 0 deletions
diff --git a/Assets/Scripts/Enemy/EnemyAttackScript.cs b/Assets/Scripts/Enemy/EnemyAttackScript.cs
new file mode 100755
index 0000000..80fa46f
--- /dev/null
+++ b/Assets/Scripts/Enemy/EnemyAttackScript.cs
@@ -0,0 +1,50 @@
+using UnityEngine;
+using System.Collections;
+
+
+/// <summary>
+/// Includes both collision attack and bullet firing
+/// </summary>
+public class EnemyAttackScript : MonoBehaviour {
+
+ GameObject player;
+
+ public float Damage = 20;
+ float timer = .5f;
+ float counter;
+ bool playerInRange;
+
+ void Start()
+ {
+ counter = 0;
+ player = GameObject.FindGameObjectWithTag("Player");
+ }
+
+ void Update()
+ {
+ counter += Time.deltaTime;
+ if (counter >= timer && playerInRange)
+ {
+ counter = 0f;
+ player.GetComponent<PlayerHealthScript>().TakeDamage(Damage);
+ }
+ }
+
+ void OnTriggerEnter2D(Collider2D other)
+ {
+ var player = other.gameObject.GetComponentInParent<PlayerHealthScript>();
+ if (player != null)
+ {
+ playerInRange = true;
+ }
+ }
+
+ void OnTriggerExit2D(Collider2D other)
+ {
+ var player = other.gameObject.GetComponentInParent<PlayerHealthScript>();
+ if (player != null)
+ {
+ playerInRange = false;
+ }
+ }
+} \ No newline at end of file