From a8fe54592f727ddad05040b82ccb490218682d7c Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 1 Feb 2020 17:06:41 +0100 Subject: Renamed to Dragon Dust --- nGJ2019/Assets/Scripts/LevelScrolling.cs | 79 -------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 nGJ2019/Assets/Scripts/LevelScrolling.cs (limited to 'nGJ2019/Assets/Scripts/LevelScrolling.cs') diff --git a/nGJ2019/Assets/Scripts/LevelScrolling.cs b/nGJ2019/Assets/Scripts/LevelScrolling.cs deleted file mode 100644 index 7ca89e3..0000000 --- a/nGJ2019/Assets/Scripts/LevelScrolling.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LevelScrolling : MonoBehaviour -{ - public int UpdateRate = -5; - public List Obstacles; - public Transform Background; - - private Vector3 initialBgPos; - private float[] backgroundSize; - - // Start is called before the first frame update - void Start() - { - ResizeBackground(); - } - - // Update is called once per frame - void Update() - { - - } - - void FixedUpdate() - { - MoveBackground(); - MoveObstacles(); - DestroyObstacles(); - } - - void ResizeBackground() - { - var sr = Background.GetComponent(); - if (sr == null) return; - - Background.localScale = new Vector3(1, 1, 1); - - var width = sr.sprite.bounds.size.x; - var height = sr.sprite.bounds.size.y; - - var worldScreenHeight = Camera.main.orthographicSize * 2.0; - var worldScreenWidth = worldScreenHeight / Screen.height * Screen.width; - - var finalHeight = (float)(worldScreenHeight / height); - var finalWidth = (float)(worldScreenWidth / width); - - Background.localScale = new Vector3(finalHeight, finalHeight, 1); - - var viewportX = Camera.main.ViewportToWorldPoint(new Vector3(0, 1, 0)).x; - Background.position = new Vector3(viewportX * -1, 0, 10); - initialBgPos = Background.position; - } - - void MoveObstacles() - { - for (int i = 0; i < Obstacles.Count; i++) - { - Obstacles[i].transform.Translate(0.01f * UpdateRate, 0, 0); - } - } - - void DestroyObstacles() - { - if (Obstacles.Count > 0 && Obstacles[0].transform.position.x < -30) - { - Destroy(Obstacles[0]); - Obstacles.RemoveAt(0); - } - } - - void MoveBackground() - { - if (Background.position.x > -initialBgPos.x) - Background.Translate(0.01f * UpdateRate, 0, 0); - else Background.position = initialBgPos; - } -} -- cgit v1.2.3