Action Classes
•
Attack Action Class:
[CreateAssetMenu(menuName = "Finite State Machine/Actions/Attack")]
public class AttackAction : Action {
public GameObject shootPrefab;
public float shootTimeInverval = 2;
private float shootTime = float.PositiveInfinity;
public override void Act(FiniteStateMachine fsm)
{
shootTime += Time.deltaTime;
if (shootTime > shootTimeInverval){
shootTime = 0;
GameObject bullet = Instantiate(shootPrefab,
fsm.transform.position, fsm.transform.rotation);
bullet.GetComponent<Rigidbody>().velocity =
fsm.transform.TransformDirection(Vector3.forward * 10);
}
}
}