Last active
February 27, 2019 08:37
-
-
Save Nesh108/78ff0424f86690105d29e5c7c11720ad to your computer and use it in GitHub Desktop.
Parallax Placer Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
[ExecuteInEditMode] | |
public class ParallaxPlacer : MonoBehaviour | |
{ | |
[SerializeField] private ParallaxSettings Settings; | |
[SerializeField] private SpriteRenderer[] ParallaxObjects; | |
void LateUpdate() | |
{ | |
for (int i = ParallaxObjects.Length - 1; i >= 0; i--) | |
{ | |
Transform poT = ParallaxObjects[i].transform; | |
poT.localPosition = new Vector3(i * Settings.XOffset, i * Settings.YOffset, i * Settings.ZOffset); | |
ParallaxObjects[i].color = new Color(ParallaxObjects[i].color.r, ParallaxObjects[i].color.g, | |
ParallaxObjects[i].color.b, | |
Settings.MinAlpha + ((Settings.MaxAlpha - Settings.MinAlpha) / ParallaxObjects.Length * (ParallaxObjects.Length - 1 - i))); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
[CreateAssetMenu(fileName = "ParallaxSettings_", menuName = "Test/ParallaxSettings")] | |
public class ParallaxSettings : ScriptableObject | |
{ | |
public float XOffset; | |
public float YOffset; | |
public float ZOffset; | |
[Range(0f, 1f)] | |
public float MinAlpha; | |
[Range(0f, 1f)] | |
public float MaxAlpha; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment