58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class FollowingEnemy : Enemy
|
|
{
|
|
public Transform target;
|
|
public float chaseRadius;
|
|
public float attackRadius;
|
|
public Transform homePosition;
|
|
|
|
public Transform[] path;
|
|
public int currentPoint;
|
|
public Transform currentGoal;
|
|
public float roundingDistance;
|
|
private Rigidbody2D myRigidbody;
|
|
public Animator anim;
|
|
public GameObject other;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
myRigidbody = GetComponent<Rigidbody2D>();
|
|
anim = GetComponent<Animator>();
|
|
target = GameObject.FindWithTag("Player").transform;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
CheckDistance();
|
|
//StartCoroutine(Timer());
|
|
}
|
|
|
|
void CheckDistance()
|
|
{
|
|
if(Vector3.Distance(target.position, transform.position) <= chaseRadius && Vector3.Distance(target.position, transform.position) > attackRadius)
|
|
{
|
|
transform.position = Vector3.MoveTowards(transform.position, target.position, moveSpeed * Time.deltaTime);
|
|
}
|
|
}
|
|
|
|
IEnumerator Timer()
|
|
{
|
|
DoDamage();
|
|
yield return new WaitForSeconds(1);
|
|
}
|
|
|
|
void DoDamage()
|
|
{
|
|
if (Vector3.Distance(target.position, transform.position) <= attackRadius)
|
|
{
|
|
int inRange = 1;
|
|
//other.GetComponent<Player>().TakeDamage(1);
|
|
}
|
|
}
|
|
}
|