Game視窗
Scene視窗
思路:圖片向左水平移動绿映,當(dāng)完全移出畫面時,移到右側(cè)畫面外穆役,繼續(xù)向左移動進入畫面雅倒。
背景圖片排隊叉跛,隊頭移出畫面時,需要排到隊尾處成為新的隊尾。新的隊尾的位置計算方法為桦踊,隊尾的位置+圖片的間隔長度。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BackgroundRoll : MonoBehaviour
{
[Tooltip("移動速度")]
public float speed;
[Tooltip("間隔")]
public float interval;
[Tooltip("位置")]
public float changePos;
// Update is called once per frame
void Update()
{
//水平移動
transform.Translate(Vector3.right * Time.deltaTime * speed);
//出畫操作
if (transform.position.x < changePos)
{
//獲取同級索引
int index = transform.GetSiblingIndex();
//防止溢出
if (index == 0)
{
index = transform.parent.childCount - 1;
}
else
{
--index;
}
//重置位置
transform.position = transform.parent.GetChild(index).position + new Vector3(interval, 0, 0);
}
}
}