using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemy : MonoBehaviour
{
public float enemySpeed;
public Transform target;
public Transform[] waypoint;
public int wayNumber;
public Transform player;
public float dist;
public float checkDist;
void Update()
{
dist = Vector2.Distance(transform.position, player.position);
if (dist > checkDist)
{
target = waypoint[wayNumber];
}
else
{
target = player;
}
Vector2 onlyXTarget=new Vector2(target.position.x,transform.position.y);
transform.position = Vector2.MoveTowards(transform.position, onlyXTarget, enemySpeed * Time.deltaTime);
if (target.position.x <= transform.position.x)//얼굴뒤집기
{
this.transform.eulerAngles = new Vector3(0, 180, 0);
}
else
{
this.transform.eulerAngles = new Vector3(0, 0, 0);
}
if(target.position.x==transform.position.x)//y축 추가로 넣어도 되는데 넣을꺼면 바닥에 딱붙여야됨
{
wayNumber++;
wayNumber = wayNumber % 2;
target = waypoint[wayNumber];
}
}
}