From 115f77bda0246a00f6e17469685c67746bdbd29d Mon Sep 17 00:00:00 2001 From: nirav Date: Sat, 12 Dec 2020 07:18:36 +0000 Subject: Initial commit --- Assets/Scripts/Enemy2/NewEnemyAttack.cs | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 Assets/Scripts/Enemy2/NewEnemyAttack.cs (limited to 'Assets/Scripts/Enemy2/NewEnemyAttack.cs') diff --git a/Assets/Scripts/Enemy2/NewEnemyAttack.cs b/Assets/Scripts/Enemy2/NewEnemyAttack.cs new file mode 100755 index 0000000..d4db669 --- /dev/null +++ b/Assets/Scripts/Enemy2/NewEnemyAttack.cs @@ -0,0 +1,49 @@ +using UnityEngine; +using System.Collections; + +public class NewEnemyAttack : MonoBehaviour { + + public bool PlayerInRange; + Rigidbody2D rb2d; + GameObject Player; + public Vector2 Origin; + NewEnemyTrigger trigger; + + void Awake() + { + Player = GameObject.FindGameObjectWithTag("Player"); + rb2d = GetComponent(); + Origin = transform.position; + trigger = GetComponentInParent(); + } + + void Start () + { + + } + + void Update () + { + if (PlayerInRange) + { + rb2d.position = Vector2.MoveTowards(rb2d.position, Player.transform.position,0.1f); + } + else if(!PlayerInRange) + { + rb2d.position = Vector2.MoveTowards(rb2d.position, Origin, 0.1f); + } + } + + void OnCollisionEnter2D(Collision2D col) + { + if (col.gameObject.GetComponentInParent()) + { + col.gameObject.GetComponentInParent().TakeDamage(10); + PlayerInRange = false; + trigger.counter = 0; + } + } + + + +} -- cgit v1.2.3