24 lines
675 B
C#
24 lines
675 B
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Platform destroyer
|
||
|
/// Original script found in: https://stackoverflow.com/questions/75924903/instantiating-and-destroying-unity-prefabs.
|
||
|
/// </summary>
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|