[更新]我尝试使用下面的建议,但我仍然有一个问题,敌人似乎同时移动,他们每次移动两次,如果已经有一个敌人在视线中。我真正想做的就是在玩家视线内的敌人行动之间有一段延迟,这样他们就不会同时移动,播放声音......等等。
更新的代码是:
private IEnumerator takeAllEnemyActions()
{
// Cycle through all enemies and have them perform their actions
if (Enemies != null && Enemies.Length > 0)
{
bool foundEnemyInLoS = false;
Enemy lastEnemy = null;
foreach (GameObject enemy in Enemies)
{
// Cache the enemies script
Enemy thisEnemy = enemy.GetComponent<Enemy>();
// If it is not this enemies turn to move then move on to the next enemy
if (thisEnemy.NextMoveTick > GameManager.Instance.CurrentTick)
{
continue;
}
// Check to see is this enemy is the first enemy in the players line of sight (If there is one)
if (!foundEnemyInLoS && thisEnemy.isInLineOfSightOfPlayer())
{
// If so then we save it for last to ensure that if any enemy is called with a delay that the last one does not make the player wait to move
foundEnemyInLoS = true;
lastEnemy = thisEnemy;
continue;
}
// At this point only enemies whose turn it is and who are not being saved for later can act
thisEnemy.TakeEnemyActions();
// If the enemy was in the players line of sight wait 200ms before continuing
if (thisEnemy.isInLineOfSightOfPlayer())
{
yield return new WaitForSeconds(0.5f);
}
}
// if there were enemies in the players line of sight then one was saved for last
// Take its action without a delay so the player can go next
if (foundEnemyInLoS)
{
lastEnemy.TakeEnemyActions();
}
}
原始问题: 在Unity3d 5中自上而下,2d,回合制roguelike,我遇到了游戏节奏的问题。我正在使用一个非常简单的状态机来控制执行但是我希望所有在同一回合中移动的敌人如果它们在玩家视线中的每个之间有一个暂停,那么动画和声音有时间没有重叠(特别是声音)。我遇到的唯一问题是在不影响动画或相机移动的情况下实现实际暂停(相机可能会滑动以跟随玩家移动并且它正在停止)。在移动到下一个敌人之前,我只需要大约100毫秒的暂停。
敌人正在EnemyManager脚本的foreach循环中执行操作
private void takeAllEnemyActions()
{
// Cycle through all enemies and have them perform their actions
if (Enemies != null && Enemies.Length > 0)
{
foreach (GameObject enemy in Enemies)
if (enemy.GetComponent<Enemy>().NextMoveTick <= GameManager.Instance.CurrentTick)
enemy.GetComponent<Enemy>().TakeEnemyActions();
}
GameManager.States.NextPlayState();
}
我尝试创建一个例程来调用每个敌人来行动但问题是其他敌人继续执行。
我尝试使用协程,但问题是游戏将继续进入下一个状态。
我甚至尝试使用Time.RealTimeSinceStartup进行while-do循环,看看它会做什么(我知道,这是一个非常糟糕的主意)
我确信这很简单,而且我只是脑部抽筋但是我一直在尝试和谷歌叮咬几个小时而没有任何进展。感谢goddness让git回滚。
有没有人对最佳方式有任何建议?我不需要有人写我的代码,我只需指向正确的方向。
由于