Basically this script is supposed to be a hiding mechanic in a locker (kinda like outlast). For some reason when I walk up to the locker (which has a trigger), nothing happens. Any suggestions? (I am using 5.5.2 if that helps).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
using UnityEngine.UI;
public class lockerHide : MonoBehaviour {
public Camera playerCam;
public Camera playerCam2;
public Camera lockerCam;
public GameObject player;
public GameObject playerGraphics;
public GameObject locker;
public Text statbar;
FirstPersonController fps;
Animator anim;
bool isHiding = false;
void Start (){
playerCam.enabled = true;
playerCam2.enabled = true;
lockerCam.enabled = false;
playerGraphics.SetActive (true);
fps = player.GetComponent<FirstPersonController> ();
anim = locker.GetComponent<Animator> ();
fps.enabled = true;
}
void Update (){
if (isHiding){
statbar.text = "Press 'E' to exit";
if (Input.GetKey(KeyCode.E)){
playerCam.enabled = true;
playerCam2.enabled = true;
lockerCam.enabled = false;
playerGraphics.SetActive (true);
fps.enabled = true;
StartCoroutine (Wait ());
}
}
}
void OnTriggerEnter (Collider col){
if (col.gameObject.tag == "Hide"){
statbar.text = "Press 'E' to hide";
if (Input.GetKey(KeyCode.E)){
playerCam.enabled = false;
playerCam2.enabled = false;
lockerCam.enabled = true;
playerGraphics.SetActive (false);
fps.enabled = false;
StartCoroutine (Wait ());
}
}
}
void OnTriggerExit (Collider col){
if (col.gameObject.tag == "Hide"){
statbar.text = "";
}
}
IEnumerator Wait (){
anim.SetTrigger ("open");
yield return new WaitForSeconds (1);
isHiding = !isHiding;
statbar.text = "";
}
}