This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
PMC_Projekt/ProjektUnity/Assets/Scripts/Enemy/EnemyMovementMelee.cs
2024-09-06 11:38:44 +02:00

38 lines
847 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Marvin Schneider
public class EnemyMovementMelee : MonoBehaviour
{
public GameObject player;
public EnemyStats enemyStats;
public float targetDistance;
private float distance;
void Start()
{
enemyStats = GetComponent<EnemyStats>();
}
void Update()
{
if(player != null){
distance = Vector2.Distance(transform.position, player.transform.position);
Vector2 direction = player.transform.position - transform.position;
direction.Normalize();
if (distance < targetDistance)
{
transform.position = Vector2.MoveTowards(transform.position, player.transform.position, enemyStats.speed * Time.deltaTime);
}
}
}
}