目錄
一、效果圖
二、講解
三、資源分享
總結(jié)
一、效果圖
游戲開始界面:
游戲畫面:
游戲結(jié)束界面:
二、講解
主要代碼如下:
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()
{
/*關(guān)閉結(jié)束界面*/
panel.SetActive(false);
}
private void OnGUI()
{
}
/*碰撞檢測*/
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "xingbiao") //如果碰到標(biāo)簽為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、結(jié)束與打包代碼
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文章來源:http://www.zghlxwxcb.cn/news/detail-522103.html
總結(jié)
以上就是我做的一個unity小游戲項目,感謝支持。文章來源地址http://www.zghlxwxcb.cn/news/detail-522103.html
到了這里,關(guān)于Unity游戲項目_3D迷宮(游戲源碼免費)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!