Game Development Reference
In-Depth Information
floatangle
=
Vector3.Angle(distVector,
transform.forward);
//If angle < 90, it is facing if(angle < 90){
//facing trigger = we can use it
st.SwitchState();
}
Listing 38: The script that allows the player to use switchable triggers
When the player presses E key, the script searches for all switchable triggers in the
scene, and finds the distance between the player and each one. If the distance is less than
activation distance set in the trigger, and the player is facing the trigger with an angle less
than 90, SwitchState() function of the trigger is called. After adding TriggerSwitcher script
to the cylinder, light switching functionality becomes ready, so you can test it. You can
also see the result int scene12 in the accompanying project.
Search WWH ::




Custom Search