Global Game Jam 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
597 B

2 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Parallax : MonoBehaviour
  5. {
  6. private float length, startpos;
  7. public GameObject cam;
  8. public float parallaxEffect;
  9. void Start()
  10. {
  11. startpos = transform.position.x;
  12. length = GetComponent<SpriteRenderer>().bounds.size.x;
  13. }
  14. // Update is called once per frame
  15. void FixedUpdate()
  16. {
  17. float dist = (cam.transform.position.x * parallaxEffect);
  18. transform.position = new Vector3(startpos + dist, transform.position.y, transform.position.z);
  19. }
  20. }