2018-04-22 23:49:43 +02:00
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Assets.Scripts.Entities.Attack {
|
|
|
|
|
[Serializable]
|
|
|
|
|
class MeleeAttack : IAttack {
|
|
|
|
|
|
2018-04-23 00:25:37 +02:00
|
|
|
|
int damage = 10;
|
2018-04-22 23:49:43 +02:00
|
|
|
|
float cooldown = 1;
|
2018-04-23 00:25:37 +02:00
|
|
|
|
float range = 2f;
|
2018-04-22 23:49:43 +02:00
|
|
|
|
GameObject owner;
|
|
|
|
|
|
|
|
|
|
public MeleeAttack(GameObject owner) {
|
|
|
|
|
this.owner = owner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Attack() {
|
|
|
|
|
RaycastHit2D hit = Physics2D.Raycast(owner.transform.position, owner.transform.localRotation * Vector3.up, range);
|
|
|
|
|
Mob m = hit.collider.gameObject.GetComponent(typeof(Mob)) as Mob;
|
|
|
|
|
if ( m != null && m.tag != owner.tag) {
|
|
|
|
|
m.InflictDamage(damage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Todo animation?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetCooldownTime() {
|
|
|
|
|
return cooldown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetRange() {
|
|
|
|
|
return range;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|