|
|
|
@ -4,33 +4,32 @@
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
using UnityEngine; |
|
|
|
|
using System.Collections; |
|
|
|
|
|
|
|
|
|
namespace Fungus |
|
|
|
|
{ |
|
|
|
|
/** |
|
|
|
|
* Attach this component to a sprite object to apply a simple parallax scrolling effect. |
|
|
|
|
* The horizontal and vertical parallax offset is calculated based on the distance from the camera to the position of the background sprite. |
|
|
|
|
* The scale parallax is calculated based on the ratio of the camera size to the size of the background sprite. This gives a 'dolly zoom' effect. |
|
|
|
|
* Accelerometer based parallax is also applied on devices that support it. |
|
|
|
|
*/ |
|
|
|
|
/// <summary> |
|
|
|
|
/// Attach this component to a sprite object to apply a simple parallax scrolling effect. |
|
|
|
|
/// The horizontal and vertical parallax offset is calculated based on the distance from the camera to the position of the background sprite. |
|
|
|
|
/// The scale parallax is calculated based on the ratio of the camera size to the size of the background sprite. This gives a 'dolly zoom' effect. |
|
|
|
|
/// Accelerometer based parallax is also applied on devices that support it. |
|
|
|
|
/// </summary> |
|
|
|
|
public class Parallax : MonoBehaviour |
|
|
|
|
{ |
|
|
|
|
/** |
|
|
|
|
* The background sprite which this sprite is layered on top of. |
|
|
|
|
* The position of this sprite is used to calculate the parallax offset. |
|
|
|
|
*/ |
|
|
|
|
/// <summary> |
|
|
|
|
/// The background sprite which this sprite is layered on top of. |
|
|
|
|
/// The position of this sprite is used to calculate the parallax offset. |
|
|
|
|
/// </summary> |
|
|
|
|
[SerializeField] protected SpriteRenderer backgroundSprite; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Scale factor for calculating the parallax offset. |
|
|
|
|
*/ |
|
|
|
|
/// <summary> |
|
|
|
|
/// Scale factor for calculating the parallax offset. |
|
|
|
|
/// </summary> |
|
|
|
|
[SerializeField] protected Vector2 parallaxScale = new Vector2(0.25f, 0f); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Scale factor for calculating parallax offset based on device accelerometer tilt angle. |
|
|
|
|
* Set this to 0 to disable the accelerometer parallax effect. |
|
|
|
|
*/ |
|
|
|
|
/// <summary> |
|
|
|
|
/// Scale factor for calculating parallax offset based on device accelerometer tilt angle. |
|
|
|
|
/// Set this to 0 to disable the accelerometer parallax effect. |
|
|
|
|
/// </summary> |
|
|
|
|
[SerializeField] protected float accelerometerScale = 0.5f; |
|
|
|
|
|
|
|
|
|
protected Vector3 startPosition; |
|
|
|
|