Browse Source

Parallax finalized

main
Tau-er\Bobbster 2 years ago
parent
commit
9a307fcc13
4 changed files with 12 additions and 10 deletions
  1. BIN
      Assets/Scenes/ParallaxTest.unity
  2. +1
    -1
      Assets/Scenes/ParallaxTest.unity.meta
  3. BIN
      Assets/Scenes/Test Scenes/THE REAL Test Scene.unity
  4. +8
    -6
      Assets/Scripts/Parallax.cs

BIN
Assets/Scenes/ParallaxTest.unity (Stored with Git LFS) View File

size 464125

Assets/Scenes/Test Scenes/THE REAL Test Scene.unity.meta → Assets/Scenes/ParallaxTest.unity.meta View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: cffcc2d96aa173a46986be2996cfc11a
guid: 2a9f0adf519794740be3df145ad6ac54
DefaultImporter:
externalObjects: {}
userData:

BIN
Assets/Scenes/Test Scenes/THE REAL Test Scene.unity (Stored with Git LFS) View File

size 151242

+ 8
- 6
Assets/Scripts/Parallax.cs View File

@ -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);
}
}

Loading…
Cancel
Save