33 lines
918 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
2020-03-18 02:00:18 +01:00
namespace UnityAtoms.Examples
2020-03-11 21:11:27 +01:00
{
2020-03-18 02:00:18 +01:00
public class EnemyShooting : MonoBehaviour
2020-03-11 21:11:27 +01:00
{
2020-03-18 02:00:18 +01:00
[SerializeField]
private StringReference _tagToTarget;
[SerializeField]
private FiniteStateMachineReference _enemyState;
[SerializeField]
private GameObject _projectile;
2020-03-15 23:18:29 +01:00
2020-03-18 02:00:18 +01:00
void Awake()
2020-03-11 21:11:27 +01:00
{
2020-03-18 02:00:18 +01:00
Transform target = null;
AtomTags.OnInitialization(() => target = AtomTags.FindByTag(_tagToTarget.Value).transform);
_enemyState.Machine.OnStateCooldown("ATTACKING", (value) =>
2020-03-15 23:18:29 +01:00
{
2020-03-18 02:00:18 +01:00
if (target)
{
var spawnPos = transform.position + transform.right;
Instantiate(_projectile, spawnPos, transform.rotation);
}
}, gameObject);
}
2020-03-11 21:11:27 +01:00
}
}