|
|
@ -4,21 +4,23 @@ using UnityEngine; |
|
|
|
|
|
|
|
public class Parallax : MonoBehaviour |
|
|
|
{ |
|
|
|
private float length, startpos; |
|
|
|
private float startpos_x, startpos_y; |
|
|
|
public GameObject cam; |
|
|
|
public float parallaxEffect; |
|
|
|
public float parallaxEffect_x; |
|
|
|
public float parallaxEffect_y; |
|
|
|
|
|
|
|
void Start() |
|
|
|
{ |
|
|
|
startpos = transform.position.x; |
|
|
|
length = GetComponent<SpriteRenderer>().bounds.size.x; |
|
|
|
startpos_x = transform.position.x; |
|
|
|
startpos_y = transform.position.y; |
|
|
|
} |
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void FixedUpdate() |
|
|
|
{ |
|
|
|
float dist = (cam.transform.position.x * parallaxEffect); |
|
|
|
float dist_x = (cam.transform.position.x * parallaxEffect_x); |
|
|
|
float dist_y = (cam.transform.position.y * parallaxEffect_y); |
|
|
|
|
|
|
|
transform.position = new Vector3(startpos + dist, transform.position.y, transform.position.z); |
|
|
|
transform.position = new Vector3(startpos_x + dist_x, startpos_y + dist_y, transform.position.z); |
|
|
|
} |
|
|
|
} |