summaryrefslogtreecommitdiff
path: root/marching/Assets/Scripts/Unit/Enemies/SpiritScript.cs
blob: f38b35466ed0da94bba81a7b2adc959d472b0892 (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
using MH;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpiritScript : UnitBase
{
    public float speed = 10f;

    protected override void Update()
    {
        base.Update();  
        UnitBase hero = UnitManager.hero;
        Vector2 pos = transform.position;
        Vector2 heroPos = hero.transform.position; 
        Vector2 dir = (heroPos - pos).normalized;
        pos += dir * Time.deltaTime * speed;
        this.GetComponent<SpriteRenderer>().flipX = dir.x < 0;

        transform.position = pos;   
    }


}