- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [CreateAssetMenu(menuName = "Finite State Machine/Action/Attack Ranged Enemy")]
- public class AttackRanged : Action
- {
- [SerializeField] private GameObject bulletPrefab;
- [SerializeField] private float bulletVelocity;
- [SerializeField] private float coolDown;
- [SerializeField] private float offSet;
- public override void Act(FiniteStateMachine fsm)
- {
- if (!fsm.floatDictionary.HasKey("shootCoolDown")) fsm.floatDictionary.SetValue("shootCoolDown", 0);
-
- if(fsm.floatDictionary.GetValue("shootCoolDown") > 0)
- {
- fsm.floatDictionary.SetValue("shootCoolDown", fsm.floatDictionary.GetValue("shootCoolDown") - Time.deltaTime);
- }
- else
- {
- fsm.floatDictionary.SetValue("shootCoolDown", coolDown);
- GameObject bullet = Instantiate(bulletPrefab, fsm.transform.position + (fsm.transform.forward * offSet), Quaternion.identity);
- bullet.GetComponent<Rigidbody>().velocity = bulletVelocity * fsm.transform.forward;
- }
- fsm.transform.LookAt(fsm.target.transform);
-
- }
- }