summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Enemy3/Enemy3AttackScript.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Enemy3/Enemy3AttackScript.cs')
-rwxr-xr-xAssets/Scripts/Enemy3/Enemy3AttackScript.cs60
1 files changed, 60 insertions, 0 deletions
diff --git a/Assets/Scripts/Enemy3/Enemy3AttackScript.cs b/Assets/Scripts/Enemy3/Enemy3AttackScript.cs
new file mode 100755
index 0000000..bd6048c
--- /dev/null
+++ b/Assets/Scripts/Enemy3/Enemy3AttackScript.cs
@@ -0,0 +1,60 @@
+using UnityEngine;
+using System.Collections;
+
+public class Enemy3AttackScript : MonoBehaviour {
+
+ public bool PlayerInRange;
+ Rigidbody2D rb2d;
+ GameObject Player;
+ public Vector2 Origin;
+ Enemy3TriggerScript trigger;
+
+ //Movement
+ public float counter;
+ public float rate;
+ public bool isRight;
+
+ void Awake()
+ {
+ Player = GameObject.FindGameObjectWithTag("Player");
+ rb2d = GetComponent<Rigidbody2D>();
+ Origin = transform.position;
+ trigger = GetComponentInParent<Enemy3TriggerScript>();
+ }
+
+ void Start()
+ {
+ counter = 0;
+ rate = 100;
+ }
+
+ void Update()
+ {
+ if (PlayerInRange)
+ {
+ counter = counter + .5f;
+ if (counter >= rate)
+ {
+ counter = 0;
+ isRight = !isRight;
+ }
+ if(isRight)
+ transform.position = new Vector3(transform.position.x + .1f, transform.position.y, transform.position.z);
+ else
+ transform.position = new Vector3(transform.position.x - .1f, transform.position.y, transform.position.z);
+ //rb2d.position = Vector2.MoveTowards(rb2d.position, Player.transform.position, 0.1f);
+ }
+ else if (!PlayerInRange)
+ {
+ rb2d.position = Origin;
+ }
+ }
+
+ void OnCollisionEnter2D(Collision2D col)
+ {
+ if (col.gameObject.GetComponentInParent<PlayerHealthScript>())
+ {
+ col.gameObject.GetComponentInParent<PlayerHealthScript>().TakeDamage(10);
+ }
+ }
+}