Game Development Reference
In-Depth Information
1. using UnityEngine;
2. using System.Collections; 3.
4. public class TriggerSwitcher : MonoBehaviour { 5.
6.
void Start () { 7.
8.
}
9.
10.
void Update () {
11.
if(Input.GetKeyDown(KeyCode.E)){
12.
//Find all switchable triggers in the scene
13.
SwitchableTrigger[] allST =
14.
FindObject-
sOfType<SwitchableTrigger>();
15.
16.
//search for suitable trigger
17.
//Suitable = near + facing
18.
foreach(SwitchableTrigger st in allST){
19.
floatdist=
20.
Vect-
or3.Distance(transform.position,
21.
st.transform.position);
22.
23.
//If distance less than activ-
ationDistance,
24.
//of the trigger, then it is
close.
25.
if(dist
<
st.activationDistance){
26.
Vector3 distVector =
27.
st.transform.position
28.
- transform.position;
29.
Search WWH ::




Custom Search