Unity游戏源码分享-Unity2D横版游戏(深海潜水艇)

这是一个使用Unity开发的2D横版小游戏,名为深海潜水艇,曾在抖音上流行。游戏通过鼠标左键控制潜水艇上升,代码结构简洁。LevelManager类是关键组件,负责管理游戏的各个阶段,如开始、暂停、重启等。项目源代码可用,可在多个平台发布。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

找到个挺有意思的小游戏Unity2D横版游戏(深海潜水艇)

这个也是曾经有段时间抖、音很火的一个小游戏。

鼠标左键点击让小艇上升

因为是unity开发的小游戏,可发布多个平台,有兴趣的拿去玩吧。

代码也是挺简单的

using UnityEngine;
using System.Collections;

public class LevelManager : MonoBehaviour 
{
	int coins 	= 0;							//Collected coins

    static LevelManager myInstance;
    static int instances = 0;

    //Retursn the instance
    public static LevelManager Instance
    {
        get
        {
            if (myInstance == null)
                myInstance = FindObjectOfType(typeof(LevelManager)) as LevelManager;

            return myInstance;
        }
    }

	//Called at the start of the game
	void Start()
	{
        //Calibrates the myInstance static variable
        instances++;

        if (instances > 1)
            Debug.Log("Warning: There are more than one Level Manager at the level");
        else
            myInstance = this;

		SaveManager.CreateAndLoadData();		        //Create or load the saved stats
		GUIManager.Instance.UpdateBestDistance();		//Update best distance at the hangar
		GUIManager.Instance.SetLevelResolution();		//Set the level for the current resolution
        MissionManager.Instance.LoadStatus();			//Load mission status
	}
	//Called when the level is started
	public void StartLevel()
	{
        StartCoroutine(LevelGenerator.Instance.StartToGenerate(1.25f, 3));	//Start the level generator
        PlayerManager.Instance.ResetStatus(true);							//Reset player status, and move the submarine to the starting position
        GUIManager.Instance.ShowStartPowerUps();								//Show the power up activation GUI
        GUIManager.Instance.ActivateMainGUI();								//Activate main GUI
	}
	//Called when the game is paused
	public void PauseGame()
	{
        PlayerManager.Instance.DisableControls();				//Disable sub controls
        LevelGenerator.Instance.Pause();							//Pause the level generator
	}
	//Called then the game is resumed
	public void ResumeGame()
	{
        PlayerManager.Instance.EnableControls();					//Enable the sub controls
        LevelGenerator.Instance.Resume();						//Resume level generation
	}
	//Called when the player is reviving
	public void Revive()
	{
        StartCoroutine(PlayerManager.Instance.Revive());			//Revive the player
	}
	//Called when a coin has been collected
	public void CoinGathered()
	{
		coins++;										//Increase coin number
        MissionManager.Instance.CoinEvent(coins);				//Notify the mission manager
	}
    //Returns the number of collected coins
    public int Coins()
    {
        return coins;
    }
	//Called when the level is restarting
	public void Restart()
	{
		coins = 0;										//Reset coin numbers

        LevelGenerator.Instance.Restart(true);					//Restart level generator
        PlayerManager.Instance.ResetStatus(true);				//Reset player status
        MissionManager.Instance.Save();							//Save mission status

        GUIManager.Instance.ShowStartPowerUps();					//Show the power up activation GUI
        GUIManager.Instance.ActivateMainGUI();					//Activate main GUI
        GUIManager.Instance.UpdateBestDistance();				//Update best distance at the hangar
	}
	//Called when quiting to the main menu from the level
	public void QuitToMain()
	{
        LevelGenerator.Instance.Restart(false);				//Disable level generator
        PlayerManager.Instance.ResetStatus(false);			//Reset player status
        MissionManager.Instance.Save();						//Save progress

        GUIManager.Instance.DeactivateMainGUI();				//Deactivate the main GUI
        GUIManager.Instance.ActivateMainMenu();				//Activate main menu
        GUIManager.Instance.UpdateBestDistance();			//Update best distance at the hangar
	}
}

项目地址:
https://download.csdn.net/download/Highning0007/87998810

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bricke

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值