41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class AttackState : State
|
|
{
|
|
[SerializeField] private State idleState;
|
|
[SerializeField] private Transform bulletSpawnPos;
|
|
protected override void EnterState()
|
|
{
|
|
Agent.AgentAnimator.SetAnimationTo(AnimationType.Attack);
|
|
Invoke("ThrowBullet",0.26f);
|
|
Invoke("BackToIdle",0.45f);
|
|
}
|
|
|
|
private void BackToIdle()
|
|
{
|
|
Agent.TransitionTo(idleState);
|
|
}
|
|
|
|
private void ThrowBullet()
|
|
{
|
|
GameObject bullet = Agent.ObjectPool.GetFromPool();
|
|
if (bullet != null)
|
|
{
|
|
audioController.Instance.PlaySFX("sfx_Attack");
|
|
bullet.gameObject.SetActive(true);
|
|
|
|
bullet.transform.position = bulletSpawnPos.position;
|
|
Rigidbody2D bulletRb = bullet.GetComponent<Rigidbody2D>();
|
|
bulletRb.velocity = new Vector2(10,bulletRb.velocity.y);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Bullet could not be created or empty");
|
|
}
|
|
}
|
|
|
|
|
|
}
|