Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / AI / FSM / Actions / AttackRanged.cs
@Rackday Rackday on 21 Aug 2024 1 KB Project Added
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [CreateAssetMenu(menuName = "Finite State Machine/Action/Attack Ranged Enemy")]
  5. public class AttackRanged : Action
  6. {
  7. [SerializeField] private GameObject bulletPrefab;
  8. [SerializeField] private float bulletVelocity;
  9. [SerializeField] private float coolDown;
  10. [SerializeField] private float offSet;
  11. public override void Act(FiniteStateMachine fsm)
  12. {
  13. if (!fsm.floatDictionary.HasKey("shootCoolDown")) fsm.floatDictionary.SetValue("shootCoolDown", 0);
  14. //if (!fsm.monoDictionary.HasKey("playerController")) fsm.monoDictionary.SetValue("playerController", fsm.target.GetComponent<PlayerController>());
  15. if(fsm.floatDictionary.GetValue("shootCoolDown") > 0)
  16. {
  17. fsm.floatDictionary.SetValue("shootCoolDown", fsm.floatDictionary.GetValue("shootCoolDown") - Time.deltaTime);
  18. }
  19. else
  20. {
  21. fsm.floatDictionary.SetValue("shootCoolDown", coolDown);
  22. GameObject bullet = Instantiate(bulletPrefab, fsm.transform.position + (fsm.transform.forward * offSet), Quaternion.identity);
  23. bullet.GetComponent<Rigidbody>().velocity = bulletVelocity * fsm.transform.forward;
  24. }
  25. fsm.transform.LookAt(fsm.target.transform);
  26. }
  27. }