[Unity学习教程] Unity游戏项目_3D迷宫(游戏源码免费)

[复制链接]
查看780 | 回复0 | 2023-8-23 11:43:21 | 显示全部楼层 |阅读模式 来自 中国北京
目录
一、效果图
二、解说
三、资源分享
总结


一、效果图

游戏开始界面:

游戏画面:
游戏竣事界面:
二、解说

重要代码如下:
1.链接代码
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine.SceneManagement;
  4. using UnityEngine;
  5. public class LoadGame : MonoBehaviour
  6. {
  7.     public void LoadingGame()//连接到游戏场景1
  8.     {
  9.         SceneManager.LoadScene(1);
  10.     }
  11.     public void LoadingBegin()//连接到开始场景0
  12.     {
  13.         SceneManager.LoadScene(0);
  14.     }
  15. }
复制代码
2.小球移动代码
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.InputSystem.HID;
  5. using UnityEngine.InputSystem.XR;
  6. using UnityEngine.InputSystem;
  7. using UnityEngine.SceneManagement;
  8. using System.Runtime.InteropServices;
  9. public class control_player: MonoBehaviour
  10. {
  11.     /*速度*/
  12.     public float moveSpeed = 0.03f;
  13.     public float turnSpeed = 10f;
  14.     public GameObject panel;
  15.     // Start is called before the first frame update
  16.     void Start()
  17.     {
  18.         /*关闭结束界面*/
  19.         panel.SetActive(false);
  20.     }
  21.     private void OnGUI()
  22.     {
  23.       
  24.     }
  25.     /*碰撞检测*/
  26.     public void OnTriggerEnter(Collider other)
  27.     {
  28.         if (other.gameObject.tag == "xingbiao") //如果碰到标签为xingbiao的物体
  29.         {
  30.             Debug.Log("TriggerWall");
  31.             panel.SetActive(true);
  32.         }
  33.         else if (other.gameObject.tag == "box")
  34.         {
  35.             Debug.Log("Triggerbox");
  36.         }
  37.     }
  38.     void Update()
  39.     {                 
  40.         /*球体移动*/
  41.         if (Input.GetKey(KeyCode.W))
  42.         {
  43.             transform.position -= new Vector3(0, 0, -moveSpeed);
  44.             transform.Rotate(turnSpeed, 0, 0);
  45.         }
  46.         if (Input.GetKey(KeyCode.S))
  47.         {
  48.             transform.position += new Vector3(0, 0, -moveSpeed);
  49.             transform.Rotate(-turnSpeed, 0, 0);
  50.         }
  51.         if (Input.GetKey(KeyCode.A))
  52.         {
  53.             transform.position += new Vector3(-moveSpeed, 0, 0);
  54.             transform.Rotate(0, 0, turnSpeed);
  55.         }
  56.         if (Input.GetKey(KeyCode.D))
  57.         {
  58.             transform.position -= new Vector3(-moveSpeed, 0, 0);
  59.             transform.Rotate(0, 0, -turnSpeed);
  60.         }
  61.         
  62.     }
  63. }
复制代码
3、竣事与打包代码
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class EndGame : MonoBehaviour
  5. {
  6.     public void EndingGame()
  7.     {
  8.    
  9. #if UNITY_EDITOR
  10.         UnityEditor.EditorApplication.isPlaying = false;//如果是在unity编译器中
  11. #else
  12.         Application.Quit();//否则在打包文件中
  13. #endif
  14. }
  15. }
复制代码

 
三、资源分享

Unity游戏项目_3D迷宫(游戏源码免费)。包罗游戏项目和打包后PC端游戏,
下载链接:https://download.csdn.net/download/weixin_45522775/87720968

总结

以上就是我做的一个unity小游戏项目,感谢支持。

来源:https://blog.csdn.net/weixin_45522775/article/details/130292097
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则