Attacks on collisions
This commit is contained in:
52
3D blobici/Assets/Scripts/Enemy/EnemyAttack.cs
Normal file
52
3D blobici/Assets/Scripts/Enemy/EnemyAttack.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyAttack : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private float attackRange = 5f;
|
||||
[SerializeField] private float attackRate = 2f;
|
||||
[SerializeField] private float attackDamage = 10f;
|
||||
[SerializeField] private float attackAngle = 45f;
|
||||
|
||||
private float lastAttackTime = 0f;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerStay(Collider other)
|
||||
{
|
||||
var player = other.GetComponent<PlayerMovement>();
|
||||
|
||||
if (player != null && Time.time - lastAttackTime > attackRate)
|
||||
{
|
||||
var health = other.GetComponent<HealthManager>();
|
||||
if (health != null)
|
||||
{
|
||||
health.ModifyHealth(-attackDamage);
|
||||
Debug.Log("Enemy attacked! Next attack in: " + (1f / attackRate) + " seconds");
|
||||
lastAttackTime = Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user