2022-04-02 00:30:13 -04:00

54 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Entity : MonoBehaviour
{
[SerializeField]private float health;
[SerializeField]private float movementSpeed;
[SerializeField]private float rotSpeed;
[SerializeField]private float fov;
[SerializeField]private float attackRange;
[SerializeField]private float attackDmg;
[SerializeField]private Transform target;
private Vector3 direction;
public Entity(float health, float movementSpeed, float rotSpeed, float attackRange, float attackDmg, Transform target){
this.health = health;
this.movementSpeed = movementSpeed;
this.rotSpeed = rotSpeed;
this.attackRange = attackRange;
this.attackDmg = attackDmg;
this.target = target;
}
private void Start() {
direction = new Vector3(1,0,0);
}
private void Update() {
MoveToTarget(transform, Time.deltaTime);
}
protected virtual void Attack(){
}
protected virtual void SpecialAttack(){
}
protected virtual void MoveToTarget(Transform transform, float deltaTime){
direction = Vector3.RotateTowards(direction, (target.position - transform.position), rotSpeed*deltaTime, 0.0f);
if( !IsInAttackRange())
transform.Translate(direction * movementSpeed* deltaTime);
}
public void SetTarget(Transform newTarget){
target = newTarget;
}
protected bool IsInAttackRange(){
return Vector2.Distance(transform.position, target.position) <= attackRange;
}
}