Unity在Unity和AI之间切换

时间:2015-11-12 04:05:47

标签: unity3d artificial-intelligence unityscript

我最近开始使用Unity进行资源管理隐形游戏。隐形部分基于回合制,类似于Hitman Go。我有一个简单的角色控制器和一个特定路径上的简单巡逻AI。然而,这些运动是实时工作的,我想将其改为基于转向。 AI应该等待玩家完成他/她的移动然后自己移动。对于玩家来说同样如此。

只有当其他部分的移动完成时,玩家和AI才能移动到相邻的航路点。

我应该怎么做?

谢谢

我写的语言是UnityScript。

2 个答案:

答案 0 :(得分:2)

作为一个非常简单的解决方案,首先您可以创建一个空的游戏对象。将其命名为TurnController。使用简单的脚本,您可以在其上添加一个布尔变量。让我们将其命名为isPlayerTurn。对于玩家移动你可以检查这个,如果真的玩家可以移动。在他/她的移动结束时(可能点击结束转弯按钮或当它达到移动的最大距离或其他东西时),您可以将isPlayerTurn设置为false。当然AI应该检查(也许在更新功能。但可以改变你的设计)如果它是真的,AI可以做它需要做的事情。在轮到它结束时,它应该将isPlayerTurn改回true。我知道这是一个非常简单的解决方案,但希望它有助于开始。我希望我没有误解你的问题。

答案 1 :(得分:0)

Write the ai as a player instance and have it emulate player input. (Instead you could also implement a common interface on both classes.)

Spawn a game object with a GameManager behaviour script that stores a reference to the current player (or ai). Then have the GameManager update the current player every frame by checking their input. If the (human) player gives input while it is not his turn, his input will just be ignored.

This way, the player and ai do not have to know if it is their turn.