diff options
Diffstat (limited to 'Assets/Scripts/Enemy2')
-rwxr-xr-x | Assets/Scripts/Enemy2/NewEnemyAttack.cs | 49 | ||||
-rwxr-xr-x | Assets/Scripts/Enemy2/NewEnemyAttack.cs.meta | 12 | ||||
-rwxr-xr-x | Assets/Scripts/Enemy2/NewEnemyHealth.cs | 34 | ||||
-rwxr-xr-x | Assets/Scripts/Enemy2/NewEnemyHealth.cs.meta | 12 | ||||
-rwxr-xr-x | Assets/Scripts/Enemy2/NewEnemyTrigger.cs | 48 | ||||
-rwxr-xr-x | Assets/Scripts/Enemy2/NewEnemyTrigger.cs.meta | 12 |
6 files changed, 167 insertions, 0 deletions
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<Rigidbody2D>(); + Origin = transform.position; + trigger = GetComponentInParent<NewEnemyTrigger>(); + } + + 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<PlayerHealthScript>()) + { + col.gameObject.GetComponentInParent<PlayerHealthScript>().TakeDamage(10); + PlayerInRange = false; + trigger.counter = 0; + } + } + + + +} diff --git a/Assets/Scripts/Enemy2/NewEnemyAttack.cs.meta b/Assets/Scripts/Enemy2/NewEnemyAttack.cs.meta new file mode 100755 index 0000000..0ea6543 --- /dev/null +++ b/Assets/Scripts/Enemy2/NewEnemyAttack.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9cf821c73c7db734ba0edc06d66be8f2 +timeCreated: 1469082882 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Enemy2/NewEnemyHealth.cs b/Assets/Scripts/Enemy2/NewEnemyHealth.cs new file mode 100755 index 0000000..4420252 --- /dev/null +++ b/Assets/Scripts/Enemy2/NewEnemyHealth.cs @@ -0,0 +1,34 @@ +using UnityEngine; +using System.Collections; + +public class NewEnemyHealth : MonoBehaviour { + + public int Health = 100; + + public GameObject DestroyAnimation; + GameObject DestroyAudio; + + void Start() + { + DestroyAudio = GameObject.FindGameObjectWithTag("EnemyDestroyAudio"); + } + + // Update is called once per frame + void Update() + { + + } + + public void TakeDamage(int damage) + { + Health -= damage; + if (Health <= 0) + { + var animation = Instantiate(DestroyAnimation, transform.position, Quaternion.identity); + DestroyAudio.GetComponent<AudioSource>().Play(); + Destroy(animation, 1f); + Destroy(transform.parent.gameObject); + } + + } +} diff --git a/Assets/Scripts/Enemy2/NewEnemyHealth.cs.meta b/Assets/Scripts/Enemy2/NewEnemyHealth.cs.meta new file mode 100755 index 0000000..3e6f6d7 --- /dev/null +++ b/Assets/Scripts/Enemy2/NewEnemyHealth.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c780c97eeb936894faf63455af12c9fd +timeCreated: 1469160284 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Enemy2/NewEnemyTrigger.cs b/Assets/Scripts/Enemy2/NewEnemyTrigger.cs new file mode 100755 index 0000000..2102049 --- /dev/null +++ b/Assets/Scripts/Enemy2/NewEnemyTrigger.cs @@ -0,0 +1,48 @@ +using UnityEngine; +using System.Collections; + +public class NewEnemyTrigger : MonoBehaviour { + + NewEnemyAttack enemy; + public float counter; + float rate = 5f; + + void Start () { + enemy = GetComponentInChildren<NewEnemyAttack>(); + } + + + void Update () { + + } + + void OnTriggerStay2D(Collider2D col) + { + if (col.GetComponentInParent<PlayerHealthScript>()) + { + counter += Time.deltaTime; + if (counter > rate) + { + counter = 0; + enemy.PlayerInRange = true; + } + + } + } + + void OnTriggerEnter2D(Collider2D col) + { + if (col.GetComponentInParent<PlayerHealthScript>()) + { + enemy.PlayerInRange = true; + } + } + + void OnTriggerExit2D(Collider2D col) + { + if (col.GetComponentInParent<PlayerHealthScript>()) + { + enemy.PlayerInRange = false; + } + } +} diff --git a/Assets/Scripts/Enemy2/NewEnemyTrigger.cs.meta b/Assets/Scripts/Enemy2/NewEnemyTrigger.cs.meta new file mode 100755 index 0000000..8f0d19a --- /dev/null +++ b/Assets/Scripts/Enemy2/NewEnemyTrigger.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 7b60d6a49475ddc46a967f9f2f5f8921 +timeCreated: 1469084262 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |