Я работаю над пошаговой файтингом. До сих пор я внедрил контроллер игрока, механику стрельбы и полосу здравоохранения. Я также начал работать над пошаговой системой, но она еще не полностью закончена, и я чувствую себя немного смущенным из-за того, как структурировать пошаговый алгоритм. < /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#
Место общения программистов C#
1738444764
Anonymous
Я работаю над пошаговой файтингом. До сих пор я внедрил контроллер игрока, механику стрельбы и полосу здравоохранения. Я также начал работать над пошаговой системой, но она еще не полностью закончена, и я чувствую себя немного смущенным из-за того, как структурировать пошаговый алгоритм. < /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
Подробнее здесь: [url]https://stackoverflow.com/questions/79405697/turn-based-game-issue[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия