-
Notifications
You must be signed in to change notification settings - Fork 1
/
Parallax.cs
26 lines (24 loc) · 1002 Bytes
/
Parallax.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Parallax : MonoBehaviour
{
public Material myMaterial;
[SerializeField] GameObject camera;
Vector3 startpos;
// Start is called before the first frame update
void Start()
{
myMaterial = GetComponent<Renderer>().material;
//camera = GameObject.FindWithTag("Main Camera");
transform.position = new Vector3(camera.transform.position.x, camera.transform.position.y, 0f);
startpos = camera.transform.position;
}
// Update is called once per frame
void FixedUpdate()
{
transform.position = new Vector3(camera.transform.position.x, camera.transform.position.y, 0f);
if (gameObject.name == "Background Fog ") { myMaterial.mainTextureOffset += new Vector2(.001f, .001f);}
else { myMaterial.mainTextureOffset = new Vector2((transform.position.x - startpos.x) / 100f, (transform.position.y - startpos.y) / 100f); }
}
}