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.

26 lines
699 B

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Parallax : MonoBehaviour
  5. {
  6. private float startpos_x, startpos_y;
  7. public GameObject cam;
  8. public float parallaxEffect_x;
  9. public float parallaxEffect_y;
  10. void Start()
  11. {
  12. startpos_x = transform.position.x;
  13. startpos_y = transform.position.y;
  14. }
  15. // Update is called once per frame
  16. void FixedUpdate()
  17. {
  18. float dist_x = (cam.transform.position.x * parallaxEffect_x);
  19. float dist_y = (cam.transform.position.y * parallaxEffect_y);
  20. transform.position = new Vector3(startpos_x + dist_x, startpos_y + dist_y, transform.position.z);
  21. }
  22. }