aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/Actors/Enemy.cs
blob: 68622985e2f2108833acb5869b1842dd56119d17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using UnityEngine;

namespace MontanaJohns.Actors
{
    [RequireComponent(typeof(Rigidbody2D))]
    public class Enemy : Actor
    {
        GameObject player;

        protected override void Awake()
        {
            base.Awake();
            player = GameObject.FindGameObjectWithTag("Player");
        }

        // Update is called once per frame
        void Update()
        {
            if (player.transform.position.x < transform.position.x) Move(-stats.speedMultiplier * 0.5f);
            else Move(stats.speedMultiplier * 0.5f);

            if (health <= 0) Destroy(gameObject);
        }

        private void OnCollisionEnter2D(Collision2D other)
        {
            if (other.gameObject.tag == "Projectile")
            {
                Debug.Log("Enemy: Hit by projectile");
                TakeDamage(1);
                Destroy(other.gameObject);
            }
        }
    }
}