(Mache nach 2-4h Schlaf weiter. Noch nicht ganz fertig, aufgrund aufgrund mangelnder Zeit durch Arbeit, damaligen privaten Problemen und damals zu viel vorgenommen).
49 lines
1.1 KiB
C#
49 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Move each layer
|
|
/// Original script: https://pastebin.com/DG5jcAMZ.
|
|
/// YouTube link: https://youtu.be/MEy-kIGE-lI.
|
|
/// </summary>
|
|
|
|
public class ParallaxBackground : MonoBehaviour
|
|
{
|
|
public ParallaxCamera parallaxCamera;
|
|
List<ParallaxLayer> parallaxLayers = new List<ParallaxLayer>();
|
|
|
|
void Start()
|
|
{
|
|
if (parallaxCamera == null)
|
|
parallaxCamera = Camera.main.GetComponent<ParallaxCamera>();
|
|
|
|
if (parallaxCamera != null)
|
|
parallaxCamera.onCameraTranslate += Move;
|
|
|
|
SetLayers();
|
|
}
|
|
|
|
void SetLayers()
|
|
{
|
|
parallaxLayers.Clear();
|
|
|
|
for (int i = 0; i < transform.childCount; i++)
|
|
{
|
|
ParallaxLayer layer = transform.GetChild(i).GetComponent<ParallaxLayer>();
|
|
|
|
if (layer != null)
|
|
{
|
|
layer.name = "Layer-" + i;
|
|
parallaxLayers.Add(layer);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Move(float delta)
|
|
{
|
|
foreach (ParallaxLayer layer in parallaxLayers)
|
|
{
|
|
layer.Move(delta);
|
|
}
|
|
}
|
|
} |