36 lines
1.0 KiB
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-20 01:29:39 +01:00
/// <summary>
/// Scipt that listens to the state of the enemy and shoots towards the Player if it's in the correct state.
/// </summary>
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
}
}