mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-24 09:08:23 -05:00
33 lines
918 B
C#
33 lines
918 B
C#
using UnityAtoms.BaseAtoms;
|
|
using UnityAtoms.FSM;
|
|
using UnityEngine;
|
|
using UnityAtoms.Tags;
|
|
|
|
namespace UnityAtoms.Examples
|
|
{
|
|
public class EnemyShooting : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private StringReference _tagToTarget;
|
|
[SerializeField]
|
|
private FiniteStateMachineReference _enemyState;
|
|
[SerializeField]
|
|
private GameObject _projectile;
|
|
|
|
void Awake()
|
|
{
|
|
Transform target = null;
|
|
AtomTags.OnInitialization(() => target = AtomTags.FindByTag(_tagToTarget.Value).transform);
|
|
|
|
_enemyState.Machine.OnStateCooldown("ATTACKING", (value) =>
|
|
{
|
|
if (target)
|
|
{
|
|
var spawnPos = transform.position + transform.right;
|
|
Instantiate(_projectile, spawnPos, transform.rotation);
|
|
}
|
|
}, gameObject);
|
|
}
|
|
}
|
|
}
|