49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System.Collections;
|
|
using DefaultNamespace;
|
|
using DG.Tweening;
|
|
using HexFiled;
|
|
using Units;
|
|
using UnityEngine;
|
|
using Weapons;
|
|
|
|
namespace Units.Views
|
|
{
|
|
public class UnitView : ViewBase
|
|
{
|
|
public UnitColor Color => _unit.Color;
|
|
|
|
|
|
protected override void OnTriggerEnter(Collider other)
|
|
{
|
|
var weaponView = other.GetComponent<WeaponView>();
|
|
if (weaponView != null && weaponView.Unit.Color != _unit.Color)
|
|
{
|
|
OnHit?.Invoke(weaponView.Weapon.modifiedDamage);
|
|
|
|
var vfx = VFXController.Instance.PlayEffect(weaponView.Weapon.VFXGameObject,
|
|
transform.position + new Vector3(0, 2, 0),
|
|
weaponView.Weapon.VFXGameObject.transform.rotation);
|
|
MusicController.Instance.AddAudioSource(vfx);
|
|
MusicController.Instance.PlayAudioClip(weaponView.Weapon.hitSound, vfx);
|
|
|
|
other.transform.DOKill();
|
|
Destroy(other.gameObject);
|
|
}
|
|
}
|
|
|
|
protected override IEnumerator Regen()
|
|
{
|
|
if (_mana >= ((Unit)_unit).Data.maxMana)
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
while (_mana < ((Unit)_unit).Data.maxMana)
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
_mana += _manaRegen;
|
|
_startRegen.Invoke();
|
|
}
|
|
}
|
|
}
|
|
} |