Я работаю над пошаговой файтингом. До сих пор я внедрил контроллер игрока, механику стрельбы и полосу здравоохранения. Я также начал работать над пошаговой системой, но она еще не полностью закончена, и я чувствую себя немного смущенным из-за того, как структурировать пошаговый алгоритм. < /P>
мог Вы помогаете мне выяснить правильный подход для обработки? < /p>
Спасибо всем! ❤ < /p>
Вот мой текущий код системы боевой системы: < /p>
`using System.Collections;`
`using UnityEngine;`
`using UnityEngine;`
`using UnityEngine;`
public enum BattleState
{
START,
PLAYER1TURN,
PLAYER2TURN,
PLAYER1WON,
PLAYER2WON,
}
public class BattleSystem : MonoBehaviour
{
public BattleState state;
public GameObject playerPrefab;
public GameObject enemyPrefab;
public Transform playerBattleStation;
public Transform enemyBattleStation;
private Unit playerUnit;
private Unit enemyUnit;
public TextMeshProUGUI dialogText;
public TextMeshProUGUI timerText;
public BattleHUD playerHUD;
public BattleHUD enemyHUD;
public float turnTimeLimit = 30f;
private float remainingTime;
private bool isTimerRunning;
public PlayerController _playerController;
public PlayerShooting _playerShooting;
[Header("Debug")] public TextMeshProUGUI Statetext;
private void Start()
{
state = BattleState.START;
StartCoroutine(SetUpBattle());
}
private void Update()
{
Statetext.text = state.ToString();
}
private IEnumerator SetUpBattle()
{
GameObject playerGO = Instantiate(playerPrefab, playerBattleStation);
playerUnit = playerGO.GetComponent();
GameObject enemyGO = Instantiate(enemyPrefab, enemyBattleStation);
enemyUnit = enemyGO.GetComponent();
// Assign PlayerController and PlayerShooting references.
_playerController = playerGO.GetComponent();
_playerShooting = playerGO.GetComponent();
if (_playerController == null)
{
Debug.LogError("PlayerController component not found on the player GameObject!");
}
else if (_playerShooting == null)
{
Debug.LogError("PlayerShooting component not found on the player GameObject!");
}
dialogText.text = playerUnit.unitName + " is come to fight you";
playerHUD.SetHUD(playerUnit);
enemyHUD.SetHUD(enemyUnit);
yield return new WaitForSeconds(1f);
state = BattleState.PLAYER1TURN;
StartPlayerTurn();
}
private void StartPlayerTurn()
{
if (state == BattleState.PLAYER1TURN)
{
dialogText.text = "Player 1's Turn: Move and Shoot!";
EnablePlayerInput(); // Enable input for Player 1.
}
else if (state == BattleState.PLAYER2TURN)
{
dialogText.text = "Player 2's Turn: Move and Shoot!";
EnablePlayerInput(); // Enable input for Player 2.
}
StartTimer();
}
private void StartTimer()
{
remainingTime = turnTimeLimit;
isTimerRunning = true;
StartCoroutine(UpdateTimer());
}
private IEnumerator UpdateTimer()
{
while (isTimerRunning && remainingTime > 0)
{
remainingTime -= Time.deltaTime;
UpdateTimerDisplay();
yield return null;
}
if (isTimerRunning && remainingTime
Подробнее здесь: https://stackoverflow.com/questions/794 ... game-issue
Задача игры на основе игры ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение