[Unity2D入门教程]简单制作仿植物大战僵尸游戏之①搭建场景

布置场景:

  众所周知,植物大战僵尸非常好玩,所以我们来制作一款类似的,名字就叫Glitch Garden。

  布置场景需要用到很多素材,这里我们在GitHub中找到一位老师的素材并把需要的导入到project面板中

GitHub - CompleteUnityDeveloper/07-Glitch-Garden: In this section we create a lane-based Tower Defense game modelled on the iconic Plants Vs Zombies game. We cover a lot of Unity's animation system, a resource management mechanic, specialised enemy types and more. This repo is part of our Complete Unity C# Developer 2D course (http://gdev.tv/cudgithub). (Ref: GL_CUD)https://github.com/CompleteUnityDeveloper/07-Glitch-Garden我们找到需要作为开场和加载动画的图片,并创建好两个创建和各自的Canvas

顺便提一嘴,创建好保存各式文件的文件夹是至关重要的,这里我就创建了很多,如果不知道意思的话可以百度翻译查一下

 这是第一个场景Splash Scene

canvas设置要改成1920 * 1080 

 Screen Match Mode改成shrink,防止分辨率改变导致画面变形

上述是对齐方式。

接下来我们进入下一个场景 

 

 这两个Text都要改成向右对齐,也是为了适应分辨率的改变


编写脚本:

我们还要创建加载场景用的空对象Scene Loader,给它一个脚本

内容如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelLoader : MonoBehaviour
{
    int currentSceneIndex;
    [SerializeField] int loadDelay = 3;
    private void Start()
    {
        currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
        if (currentSceneIndex == 0)
        {
            StartCoroutine(WaitForTime());
        }
    }
    IEnumerator WaitForTime()
    {
        yield return new WaitForSeconds(loadDelay); //使用协成延迟调用场景
        SceneManager.LoadScene(currentSceneIndex + 1);
    }
    public void LoadNextScene()
    {
        SceneManager.LoadScene(currentSceneIndex + 1);
    }
}

 然后再创建一个作为播放音乐的 Load Sound

然后把它们两个都做成prefab放在两个场景

 

然后放在bulid setting中的Scene in bulid


游戏效果:

 过了三秒后自动切换场景

猜你喜欢

转载自blog.csdn.net/dangoxiba/article/details/124112667
今日推荐