32 lines
711 B
C#
32 lines
711 B
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class Enemy : MonoBehaviour
|
||
|
{
|
||
|
private Player player;
|
||
|
[SerializeField] private float moveSpeed;
|
||
|
void Start()
|
||
|
{
|
||
|
player = FindFirstObjectByType<Player>();
|
||
|
if(player == null)
|
||
|
{
|
||
|
//TODO
|
||
|
Destroy(gameObject);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
private void FixedUpdate()
|
||
|
{
|
||
|
Vector2 direction = (player.transform.position - transform.position).normalized;
|
||
|
Vector2 targePosition = (Vector2)transform.position + direction * moveSpeed;
|
||
|
transform.position = targePosition;
|
||
|
}
|
||
|
}
|