Unity游戏项目_3D迷宫(游戏源码免费)

目录

一、效果图

二、讲解

三、资源分享

总结


一、效果图

游戏开始界面:

游戏画面:

游戏结束界面:

二、讲解

主要代码如下:

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小游戏项目,感谢支持。

猜你喜欢

转载自blog.csdn.net/weixin_45522775/article/details/130292097