holopy3/Assets/ShatterableGlass/Demo/Scripts/UseArea.cs
2020-12-10 15:25:12 +01:00

31 lines
No EOL
786 B
C#

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);
}
}