MOD: Enemy AI
MOD: Player Shooting MOD: Damage Player and Enemy
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyMovement : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
44
ProjektUnity/Assets/Scripts/Enemy/EnemyMovementMelee.cs
Normal file
44
ProjektUnity/Assets/Scripts/Enemy/EnemyMovementMelee.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyMovementMelee : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
public EnemyStats enemyStats;
|
||||
public float targetDistance;
|
||||
|
||||
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
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58a007a46183a8947a29e53b7c347d41
|
||||
guid: 52630bacc6c11024e9cbe915465fc6d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -8,16 +8,31 @@ public class EnemyStats : MonoBehaviour
|
||||
public Enemy enemy;
|
||||
public float health = 0;
|
||||
public float speed = 0;
|
||||
public float damage = 0;
|
||||
|
||||
private void Start() {
|
||||
health = enemy.currentHealth;
|
||||
speed = enemy.currentSpeed;
|
||||
health = enemy.getCurrentHealth();
|
||||
speed = enemy.getCurrentSpeed();
|
||||
damage = enemy.getDamage();
|
||||
}
|
||||
|
||||
//Für Später
|
||||
/* private void OnCollisionEnter2D(Collision2D other) {
|
||||
if (other.gameObject.CompareTag("Sword") || other.gameObject.CompareTag("Bullet")){
|
||||
private void OnTriggerEnter2D(Collider2D other) {
|
||||
if (other.gameObject.CompareTag("Bullet")){
|
||||
BulletScript bulletScript = other.gameObject.GetComponent<BulletScript>();
|
||||
health -= bulletScript.weapon.getDamage();
|
||||
|
||||
if (health <= 0)
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
} else if(other.gameObject.CompareTag("Player")){
|
||||
speed = 0f;
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other) {
|
||||
speed = enemy.getCurrentSpeed();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user