我对 Unity 2d 很陌生。如何在 Unity 2d 中创建一个问题作为移动角色的障碍?
请注意,问题的数量最多可达 5 个,随着角色的前进而出现,并且还会有玩家选择最多移动的选项。如果他选择了错误的选项,最终的结果可能会算在最后,或者他可能会失去生命。
由于没有任何代码要查看,因此很难确切知道您想要什么,但是这样的事情应该可以工作:
在您控制播放器的脚本中:
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
}
}
}
这是对我们问题的一个非常广泛的答案,当然您需要对其进行编辑以适合您的需要。