背景在製作時可以拆分開來做出景深效果,可以調整Order in Layer的數值讓每個景物有不同的距離並用腳本讓各景物的移動速度有所差距。
要先將背景素材的Wrap Mode改成Repeat,才能讓圖片有loop效果。
待更
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BackGroundLoop : MonoBehaviour {
public float BGspeed = 0.1f;
public Renderer BG;
void Start()
{
BG = GetComponent<Renderer>();
}
void Update()
{
BG.material.mainTextureOffset = new Vector2(Time.time * BGspeed, 0);
}
}
待更
參考資料
https://docs.unity3d.com/ScriptReference/Renderer-material.html
https://jerrard-liu.blogspot.com/2015/10/unity-2d.html
https://forum.gamer.com.tw/Co.php?bsn=60602&sn=7109
https://book.king011.com/view/zh-Hant/view/devgame-unity-2d-example/parallax-scrolling