C# Unity Mobile 2D-选择按钮A,然后从按钮B调用功能
我目前正在开发一款2D Android小游戏,我的关卡选择场景有些问题。 这样做的目的是将多个级别进行布局,当您选择其中一个级别时,它会高亮显示,然后按下屏幕底部的“播放”按钮以加载相应的场景。(见附图) 现在我不太清楚如何选择按钮,然后按play来运行它的功能。我对Unity中的触摸控制不是很有经验。有什么想法吗?提前谢谢。C# Unity Mobile 2D-选择按钮A,然后从按钮B调用功能,c#,android,unity3d,C#,Android,Unity3d,我目前正在开发一款2D Android小游戏,我的关卡选择场景有些问题。 这样做的目的是将多个级别进行布局,当您选择其中一个级别时,它会高亮显示,然后按下屏幕底部的“播放”按钮以加载相应的场景。(见附图) 现在我不太清楚如何选择按钮,然后按play来运行它的功能。我对Unity中的触摸控制不是很有经验。有什么想法吗?提前谢谢。 我建议您创建一个UIManager或类似的东西来处理所有与UI相关的功能。然后在UIManager脚本中,可以有如下内容: public string level;//T
我建议您创建一个
UIManager
或类似的东西来处理所有与UI相关的功能。然后在UIManager
脚本中,可以有如下内容:
public string level;//This would store the name of the level that was clicked on
//Create functions to assign the name when the button is clicked on
public void Level1() //This function would be assigned to level 1 button
{
level = "Level1";
}
public void Level2() //This function would be assigned to level 2 button
{
level = "Level2";
}
您可以根据需要为级别创建任意数量的函数。然后,对于播放按钮,您可以使用以下功能:
public void PlayGame()
{
switch(level)
{
case "Level1":
SceneManager.LoadScene(//Input the scene for level 1 here);
break:
//You can then create cases for the other levels too.
default:
break;
}
}
然后,将脚本分配给检查器中OnClick()
部分中按钮的按钮组件下的每个按钮。从这里,您可以将每个功能分配给相应的按钮。另外,确保函数设置为public,以便您能够在检查器中看到它们
对于单击按钮时的高亮显示,您还可以在
按钮下的检查器中更改该选项。从那里,您可以将过渡样式设置为颜色更改、动画或交换精灵。哦,这就像一个魔咒!我永远欠你的债,善良的陌生人:D