MOD: Sprites hinzugefügt
MOD: Gegner platziert
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Marvin Schneider
|
||||
public class EnemyMovementMelee : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
@@ -10,34 +11,26 @@ public class EnemyMovementMelee : MonoBehaviour
|
||||
|
||||
private float distance;
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
||||
void Start()
|
||||
{
|
||||
enemyStats = GetComponent<EnemyStats>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(player != null){
|
||||
// Calculate the distance between the enemy and the player
|
||||
|
||||
distance = Vector2.Distance(transform.position, player.transform.position);
|
||||
|
||||
// Get the direction to the player by subtracting the enemy's position from the player's position
|
||||
Vector2 direction = player.transform.position - transform.position;
|
||||
direction.Normalize(); // Normalize the direction vector
|
||||
direction.Normalize();
|
||||
|
||||
// Calculate the angle to rotate the enemy to face the player
|
||||
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
|
||||
|
||||
// If the player is within a certain range, move towards them
|
||||
if (distance < targetDistance)
|
||||
{
|
||||
// Move the enemy towards the player's position
|
||||
transform.position = Vector2.MoveTowards(transform.position, player.transform.position, enemyStats.speed * Time.deltaTime);
|
||||
|
||||
// Rotate the enemy to face the player
|
||||
transform.rotation = Quaternion.Euler(Vector3.forward * angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Marvin Schneider
|
||||
public class EnemyStats : MonoBehaviour
|
||||
{
|
||||
public Enemy enemy;
|
||||
@@ -16,7 +17,7 @@ public class EnemyStats : MonoBehaviour
|
||||
damage = enemy.getDamage();
|
||||
}
|
||||
|
||||
//Für Später
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other) {
|
||||
if (other.gameObject.CompareTag("Bullet")){
|
||||
BulletScript bulletScript = other.gameObject.GetComponent<BulletScript>();
|
||||
|
Reference in New Issue
Block a user