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

31 lines
786 B
C#
Raw Normal View History

2020-12-10 14:25:12 +00:00
using UnityEngine;
using System.Collections;
// If Player within triggr, and player pressed E then Glass will shatter.
public class UseArea : MonoBehaviour
{
// Player in trigger?
bool PlayerIsHere = false;
// Target Glass
public ShatterableGlass Glass;
void OnTriggerEnter(Collider Intruder)
{
if (Intruder.tag == "Player")
PlayerIsHere = true;
}
void OnTriggerExit(Collider Intruder)
{
if (Intruder.tag == "Player")
PlayerIsHere = false;
}
// This funtion called when Player pressed E.
public void Use()
{
// Do not attepmt to shatter glass, if Glass already Destroyed().
if (Glass && PlayerIsHere)
Glass.Shatter(Vector2.zero, Glass.transform.forward);
}
}