using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// This script defines the size of the ‘Boundary’ depending on Viewport. When objects go beyond the ‘Boundary’, they are destroyed or deactivated.
///
public class Boundary : MonoBehaviour {
BoxCollider2D boundareCollider;
//receiving collider's component and changing boundary borders
private void Start()
{
boundareCollider = GetComponent();
ResizeCollider();
}
//changing the collider's size up to Viewport's size multiply 1.5
void ResizeCollider()
{
Vector2 viewportSize = Camera.main.ViewportToWorldPoint(new Vector2(1, 1)) * 2;
viewportSize.x *= 1.5f;
viewportSize.y *= 1.5f;
boundareCollider.size = viewportSize;
}
//when another object leaves collider
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.tag == "Projectile")
{
Destroy(collision.gameObject);
}
else if (collision.tag == "Bonus")
Destroy(collision.gameObject);
}
}