-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackgroundScroll.cs
39 lines (32 loc) · 1.38 KB
/
BackgroundScroll.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace LoneX.TchilaVirus
{
public class BackgroundScroll : MonoBehaviour
{
public float length , height , startPosX , startPosY;
public GameObject cam;
public float parallaxEffect;
private void Start()
{
startPosX = transform.position.x;
startPosY = transform.position.y;
this.transform.position = new Vector3(startPosX , startPosY , this.transform.position.z);
length = transform.GetChild(1).position.x;
height = transform.GetChild(6).position.y;
}
private void Update()
{
float tempX = (cam.transform.position.x *(1 - parallaxEffect));
float tempY = (cam.transform.position.y *(1 - parallaxEffect));
float distX = (cam.transform.position.x * parallaxEffect);
float distY = (cam.transform.position.y * parallaxEffect);
transform.position = new Vector3 (startPosX + distX , startPosY + distY , transform.position.z);
if(tempX > startPosX + length ) startPosX += length;
else if (tempX < startPosX - length ) startPosX -= length;
if(tempY > startPosY + height ) startPosY += height;
else if (tempY < startPosY - height ) startPosY -= height;
}
}
}