我是Unity 2d的新手。如何在Unity 2d中为移动角色创建问题作为障碍?
请注意,问题最多可达5个,显示为前方角色,也可选择玩家最多选择一个移动。最终的结果可能在最后计算,或者如果他选择了错误的选项,他可能会失去生命。
答案 0 :(得分:0)
很难确切地知道你想要什么,因为你没有任何代码要审查,但这样的事情应该有效:
在控制播放器的脚本中:
public bool canMove = true;
if(canMove) {
//Your code allowing the player to move
}
在你的脚本中管理障碍:
public PlayerController playerController;
public bool didSolveCorrectly;
public int punishments;
void StartObstacle(int type) {
playerController.canMove = false;
switch (type) {
//Cases and other stuff about the puzzles. I recommend making methods later on in the code and calling them here, so that it's more organized.
}
}
void CompleteObstacle(bool correct, int punishmentType) {
if (correct) {
playerController.canMove = true;
}
else {
switch (punishmentType) {
//More cases governing what should happen to the player if they failed the question
}
}
}
这是我们问题的一个非常广泛的答案,当然你需要编辑它以适合你的需要。