add unity project
add example for FSM
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public class FireButton : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private InputAction _fireAction;
|
||||
|
||||
private bool _isFired = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_fireAction.performed += OnFired;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_isFired = _isFired || _fireAction.triggered;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
// movement
|
||||
// rotation
|
||||
// fire
|
||||
if (_isFired)
|
||||
{
|
||||
_isFired = false;
|
||||
// spawn bullet
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFired(InputAction.CallbackContext ctx)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_fireAction.Enable();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_fireAction.Disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user