You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
using UnityEngine;
|
|
|
|
namespace Skill_V2
|
|
{
|
|
[CreateAssetMenu(fileName = "SpawnBullet", menuName = "ScriptableObject/Skill/State/SpawnBullet")]
|
|
public class SpawnBullet : SkillState
|
|
{
|
|
[SerializeField] Bullet bulletPrefab;
|
|
[SerializeField, TagSelector] string[] filterTags;
|
|
|
|
Bullet bulletInstance;
|
|
SingleTargetFinder targetFinder;
|
|
|
|
public override void Enter(StateHandler excutor)
|
|
{
|
|
if(targetFinder is null)
|
|
targetFinder = new SingleTargetFinder(filterTags);
|
|
|
|
bulletInstance = Instantiate(bulletPrefab, Owner.CenterPivot, Quaternion.identity);
|
|
bulletInstance.AddTagFilter(filterTags);
|
|
bulletInstance.OnEnterCollider += HandleCollide;
|
|
|
|
if (targetFinder.TryFindNearest(Owner.CenterPivot, out var target))
|
|
{
|
|
bulletInstance.Fire(target.transform);
|
|
}
|
|
else
|
|
{
|
|
bulletInstance.HeadDirection = Owner.LookDirection;
|
|
bulletInstance.Fire();
|
|
}
|
|
|
|
IsDone = true;
|
|
}
|
|
|
|
public override void Stop()
|
|
{
|
|
if (bulletInstance != null)
|
|
{
|
|
Destroy(bulletInstance.gameObject);
|
|
}
|
|
|
|
bulletInstance = null;
|
|
}
|
|
|
|
private void HandleCollide(Collider2D other)
|
|
{
|
|
if (other.gameObject.TryGetComponent(out CreatureBase target))
|
|
{
|
|
//TODO : Get damage from skill, this is temporary
|
|
BattleMgr.Instance.SendDamage(target, 4000, 0, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|