From fb2703b646d22bd4502fab6f0ca58cb922d1ed2c Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Fri, 8 Apr 2022 17:24:16 -0500 Subject: wip: no regerts fix jump; race condition(ish) in jump/fall/land events (?) impl trigger animations on events refactor control, (follow) camera, anim handlers into interfaces impl controller pattern for controls (FSM using lambdas + interfaces) come up with the rest of the todos --- Assets/Scripts/InfiniteBackground.cs | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Assets/Scripts/InfiniteBackground.cs (limited to 'Assets/Scripts/InfiniteBackground.cs') diff --git a/Assets/Scripts/InfiniteBackground.cs b/Assets/Scripts/InfiniteBackground.cs new file mode 100644 index 0000000..d587040 --- /dev/null +++ b/Assets/Scripts/InfiniteBackground.cs @@ -0,0 +1,41 @@ +using System.Collections; +using UnityEngine; + +public class InfiniteBackground : MonoBehaviour +{ + [SerializeField] GameObject cam; + [SerializeField] float parallaxEffect = 0.3f; + + internal Vector2 pos; + internal float spriteExtentX; + + void Start() + { + Vector2 pos = transform.position; + spriteExtentX = GetComponent().bounds.size.x / 2; + } + + void FixedUpdate() + { + float camExtentX = Camera.main.orthographicSize * Screen.width / Screen.height; + float newPosX = pos.x + (cam.transform.position.x * parallaxEffect); + + if (newPosX + spriteExtentX <= Camera.main.transform.position.x + camExtentX) + { + var clone = Instantiate(this.gameObject); + clone.transform.position = new Vector3(newPosX + spriteExtentX, transform.position.y, transform.position.z); + } + else if (newPosX - spriteExtentX >= Camera.main.transform.position.x - camExtentX) + { + var clone = Instantiate(gameObject); + clone.transform.position = new Vector3(newPosX - spriteExtentX, transform.position.y, transform.position.z); + } + + transform.position = new Vector3(newPosX, transform.position.y, transform.position.z); + } + + void OnBecameInvisible() + { + Destroy(gameObject); + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2