holopy3/Assets/ShatterableGlass/Demo/Scripts/Trigger.cs

33 lines
844 B
C#
Raw Permalink Normal View History

2020-12-10 14:25:12 +00:00
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);
}
}
}