-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraMovement.cs
More file actions
29 lines (22 loc) · 773 Bytes
/
CameraMovement.cs
File metadata and controls
29 lines (22 loc) · 773 Bytes
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour
{
private float lenght, starpos;
public GameObject cam;
public float parallaxEffect;
void Start()
{
starpos = transform.position.x;
lenght = GetComponent<SpriteRenderer>().bounds.size.x;
}
private void FixedUpdate()
{
float temp = (cam.transform.position.x * (1 - parallaxEffect));
float dist = (cam.transform.position.x * parallaxEffect);
transform.position = new Vector3(starpos = dist, transform.position.y, transform.position.z);
if (temp > starpos + lenght) starpos += lenght;
else if (temp < starpos - lenght) starpos -= lenght;
}
}