1.新建一个名为MainMenu的C#脚本,修改编码后拖动到主摄像机,并给主摄像机添加一个AudioSource声音源作为背景音乐。将音乐文件赋值给Audio Clip属性。

Unity3D之主菜单

2.创建一个CommonHelper类,用于封装常用的方法,比如让窗口的位置居中显示:

 1 using System;
 2 using UnityEngine;
 3 namespace AssemblyCSharp
 4 {
 5     public class CommonHelper
 6     {
 7         public static Rect GetCenterRect(float width,float height)
 8         {
 9             float left =(Screen.width-width)/2;    
10             float top =(Screen.height-height)/2;
11             return new UnityEngine.Rect(left,top,width,height);
12         }
13     }
14 }
CommonHelper

相关文章: