54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
public class BGManager : MonoBehaviour
|
|
{
|
|
//private float height;
|
|
public Vector3 upV3;
|
|
public Vector3 centerV3;
|
|
public Vector3 downV3;
|
|
private float currHeight;
|
|
public float speed;
|
|
public float height;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
//设置背景布局
|
|
//height = Screen.height*3;
|
|
upV3 = Vector3.up * Screen.height*2;
|
|
centerV3 = Vector3.up * Screen.height;
|
|
downV3 = Vector3.zero;
|
|
upV3 = CoordinateTransformation.ScreenToCamera(upV3);
|
|
centerV3 = CoordinateTransformation.ScreenToCamera(centerV3);
|
|
downV3 = CoordinateTransformation.ScreenToCamera(downV3);
|
|
transform.GetChild(0).position = upV3;
|
|
transform.GetChild(1).position = centerV3;
|
|
transform.GetChild(2).position = downV3;
|
|
height = upV3.y - centerV3.y;
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
float step = Time.deltaTime * speed;
|
|
currHeight += step;
|
|
foreach (Transform t in transform)
|
|
{
|
|
t.Translate(Vector3.down * step);
|
|
}
|
|
|
|
if (currHeight > height*1.3f)
|
|
{
|
|
|
|
currHeight -= height;
|
|
Vector3 v3 = transform.GetChild(2).position;
|
|
v3.y += height*3;
|
|
transform.GetChild(2).position= v3;
|
|
transform.GetChild(2).SetAsFirstSibling();
|
|
}
|
|
|
|
|
|
}
|
|
}
|