30 lines
796 B
C#
Raw Normal View History

2020-03-11 21:11:27 +01:00
using UnityAtoms.BaseAtoms;
using UnityAtoms.FSM;
using UnityEngine;
2020-03-15 23:18:29 +01:00
using UnityAtoms.Tags;
2020-03-11 21:11:27 +01:00
public class EnemyShooting : MonoBehaviour
{
2020-03-15 23:18:29 +01:00
[SerializeField]
private StringReference _tagToTarget;
2020-03-11 21:11:27 +01:00
[SerializeField]
private FiniteStateMachineReference _enemyState;
[SerializeField]
private GameObject _projectile;
void Awake()
{
2020-03-15 23:18:29 +01:00
Transform target = null;
AtomTags.OnInitialization(() => target = AtomTags.FindByTag(_tagToTarget.Value).transform);
2020-03-11 21:11:27 +01:00
_enemyState.Machine.OnStateCooldown("ATTACKING", (value) =>
{
2020-03-15 23:18:29 +01:00
if (target)
{
var spawnPos = transform.position + transform.right;
Instantiate(_projectile, spawnPos, transform.rotation);
}
2020-03-11 21:11:27 +01:00
}, gameObject);
}
}