C#实战课程---太空大战(第一课:创建项目)

一、项目选择

URP模板,版本为2020.2

二、项目整理

导入资源包,清理URP多余的Sample示例和配置文件,只保留

打开PackageManager清理多余的插件包,只保留

 

 三、设置场景

点击2D按钮,设置场景相机参数

投放3D机资源到场景中,复制光源重置TransForm,重命名为Directional Light Fill,调整颜色烘托气氛。

四、关键一步让背景动起来

原理:材质的Offset变化,会产生相对移动错觉,但前提是材质贴图是无缝的。

在场景中创建Quad,在文件夹中创建一个Material,将背景图片设置为Default,拖动到材质球上,将材质球赋予Quad,根据图片的尺寸

设置Quad尺寸为同样的比例:20.48比8.22。

创建脚本,BackGroundScroller,赋予Quad,将Quad重命名为Simple BackGround。

附上代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BackGroundScroller : MonoBehaviour
{
    [Tooltip("材质偏移滚动速度")]
    [SerializeField]private Vector2 scrollVelocity;
    private Material _material;
    // Start is called before the first frame update
    void Awake()
    {
        _material = GetComponent<Renderer>().material;
    }

    // Update is called once per frame
    void Update()
    {
        _material.mainTextureOffset += scrollVelocity * Time.deltaTime;
    }
}

课程来自B站阿严

地址:[Unity] 横版卷轴射击游戏 制作教程 Ep.01 项目创建 | 简易背景卷动 | URP模板 | 独立游戏 | 游戏开发_哔哩哔哩_bilibili

猜你喜欢

转载自blog.csdn.net/m0_70379630/article/details/126373317