32 lines
844 B
C#
32 lines
844 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
// Glass will be shattered when Player steps in the trigger.
|
|
public class Trigger : MonoBehaviour
|
|
{
|
|
|
|
// Target Glass
|
|
public ShatterableGlass Glass;
|
|
|
|
public delegate void ShatterDelegate();
|
|
public static event ShatterDelegate OnGlassTriggered;
|
|
|
|
|
|
void OnTriggerEnter(Collider Intruder)
|
|
{
|
|
|
|
// Check if Intruder is Player:
|
|
if (Intruder.tag == "Player" || Intruder.tag == ("Ball"))
|
|
{
|
|
// Do not attepmt to shatter glass, if Glass already Destroyed().
|
|
if (Glass)
|
|
{
|
|
OnGlassTriggered.Invoke();
|
|
Glass.Shatter(Vector2.zero, Glass.transform.forward);
|
|
}
|
|
// Destroy() trigger itself.
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|