Unity 游戏黑暗之光笔记
第一章 完善场景
1. 导入资地形、地貌资源,新建场景,导入地形、地貌prefab
2. 设置相机与视野匹配
选中主摄像机,点选菜单栏中GameObject > Align With View
3. 添加灯光
Direction light > Intensity 光照强度
4. 添加鼠标指针
- File > Build Settings > Player Settings
5. 添加水面
6. 实现镜头缓慢拉近的效果
public float speed = 10; //设置速度 private float endZ = -20; //设置结束坐标 void Start () { void Update () { //判断坐标小于结束坐标 if (transform.position.z < endZ) { //还没有达到目标位置,需要移动 transform.Translate( Vector3.forward*speed*Time.deltaTime); } }
7. 添加雾
- Window > Rendering > Lighting Settings > other Settings
8. 使用UGUI和白色背景给场景添加渐显效果
UIFadeTest.Instance.UIShow();
public float fadeSpeed = 10; //速度 private CanvasGroup canvasGroup; private float alpha = 1.0f; private static UIFadeTest instance; //设置单例 public static UIFadeTest Instance { get { return instance; } } void Start() { instance = this; canvasGroup = this.gameObject.GetComponent<CanvasGroup>(); } // Update is called once per frame void Update() { if (alpha != canvasGroup.alpha) { canvasGroup.alpha = Mathf.Lerp(canvasGroup.alpha, alpha, fadeSpeed * Time.deltaTime); if (Mathf.Abs(canvasGroup.alpha - alpha) < 0.01f) { canvasGroup.alpha = alpha; } } } public void UIShow() { alpha = 0; canvasGroup.blocksRaycasts = false; } }
9. 添加鼠标点击事件
在点击Press后显示按钮,先让newgame和loadgame按钮不激活
private bool isAnyKeyDown = false;//表示是否有任何按键按下 private GameObject buttonContainer; void Start() { buttonContainer = this.transform.parent.Find("buttonContainer").gameObject; } // Update is called once per frame void Update() { //判定没有按键按下 if (isAnyKeyDown == false) { //如果按下显示案件 if (Input.anyKey) { { ShowButton(); } } } //开始和加载按钮显示方法 void ShowButton() { buttonContainer.SetActive(true); this.gameObject.SetActive(false); isAnyKeyDown = true; } }
newgame和loadgame按钮鼠标事件
//开始新游戏 public void OnNewGame() { PlayerPrefs.SetInt("DataFromSave", 0); // 加载我们的选择角色的场景 2 } //加载已经保存的游戏 public void onl oadGame() { PlayerPrefs.SetInt("DataFromSave", 1); //DataFromSave表示数据来自保存 //加载我们的play场景3 }
10. 给开始场景添加背景声音和按钮点击的声音
-
在主摄像机添加BGM音乐
在newgame和loadgame按钮上分别添加playsound脚本
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。