using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// Platform destroyer /// Original script found in: https://stackoverflow.com/questions/75924903/instantiating-and-destroying-unity-prefabs. /// public class OffScreenDestroyPlatform : MonoBehaviour { public static Vector2? screenBounds; private void FixedUpdate() { if (screenBounds == null) screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z)); if (transform.position.x < screenBounds.Value.x * 5) { Destroy(gameObject); } } }