目录
一、效果图
二、解说
三、资源分享
总结
一、效果图
游戏开始界面:

游戏画面:
游戏竣事界面:
二、解说
重要代码如下:
1.链接代码
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.SceneManagement;
- using UnityEngine;
- public class LoadGame : MonoBehaviour
- {
- public void LoadingGame()//连接到游戏场景1
- {
- SceneManager.LoadScene(1);
- }
- public void LoadingBegin()//连接到开始场景0
- {
- SceneManager.LoadScene(0);
- }
- }
复制代码 2.小球移动代码
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.InputSystem.HID;
- using UnityEngine.InputSystem.XR;
- using UnityEngine.InputSystem;
- using UnityEngine.SceneManagement;
- using System.Runtime.InteropServices;
- public class control_player: MonoBehaviour
- {
- /*速度*/
- public float moveSpeed = 0.03f;
- public float turnSpeed = 10f;
- public GameObject panel;
- // Start is called before the first frame update
- void Start()
- {
- /*关闭结束界面*/
- panel.SetActive(false);
- }
- private void OnGUI()
- {
-
- }
- /*碰撞检测*/
- public void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.tag == "xingbiao") //如果碰到标签为xingbiao的物体
- {
- Debug.Log("TriggerWall");
- panel.SetActive(true);
- }
- else if (other.gameObject.tag == "box")
- {
- Debug.Log("Triggerbox");
- }
- }
- void Update()
- {
- /*球体移动*/
- if (Input.GetKey(KeyCode.W))
- {
- transform.position -= new Vector3(0, 0, -moveSpeed);
- transform.Rotate(turnSpeed, 0, 0);
- }
- if (Input.GetKey(KeyCode.S))
- {
- transform.position += new Vector3(0, 0, -moveSpeed);
- transform.Rotate(-turnSpeed, 0, 0);
- }
- if (Input.GetKey(KeyCode.A))
- {
- transform.position += new Vector3(-moveSpeed, 0, 0);
- transform.Rotate(0, 0, turnSpeed);
- }
- if (Input.GetKey(KeyCode.D))
- {
- transform.position -= new Vector3(-moveSpeed, 0, 0);
- transform.Rotate(0, 0, -turnSpeed);
- }
-
- }
- }
复制代码 3、竣事与打包代码
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class EndGame : MonoBehaviour
- {
- public void EndingGame()
- {
-
- #if UNITY_EDITOR
- UnityEditor.EditorApplication.isPlaying = false;//如果是在unity编译器中
- #else
- Application.Quit();//否则在打包文件中
- #endif
- }
- }
复制代码
三、资源分享
Unity游戏项目_3D迷宫(游戏源码免费)。包罗游戏项目和打包后PC端游戏,
下载链接:https://download.csdn.net/download/weixin_45522775/87720968
总结
以上就是我做的一个unity小游戏项目,感谢支持。
来源:https://blog.csdn.net/weixin_45522775/article/details/130292097
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |