Here is my Player Collisions script:
using UnityEngine;
using System.Collections;
public class PlayerCollisions : MonoBehaviour {
GameObject currentDoor;
void Update () {
RaycastHit hit;
if(Physics.Raycast (transform.position, transform.forward, out hit, 3)) {
if(hit.collider.gameObject.tag == "playerdoor") {
currentDoor= hit.collider.gameObject;
currentDoor.SendMessage ("DoorCheck");
}
}
}
And this Door Manager script:
using UnityEngine;
using System.Collections;
public class DoorManager : MonoBehaviour {
bool doorIsOpen = false;
float doorTimer = 0.0f;
public float doorOpenTime = 3.0f;
public AudioClip doorOpenSound;
public AudioClip doorShutSound;
// Use this for initialization
void Start () {
doorTimer = 0.0f;
}
// Update is called once per frame
void Update () {
if(doorIsOpen){
doorTimer += Time.deltaTime;
if(doorTimer > doorOpenTime){
Door(doorShutSound, false, "doorshut");
doorTimer = 0.0f;
}
}
}
void DoorCheck(){
if(!doorIsOpen){
Door(doorOpenSound,true, "dooropen");
}
}
void Door(AudioClip aClip, bool openCheck, string animName){
audio.PlayOneShot(aClip);
doorIsOpen = openCheck;
transform.parent.gameObject.animation.Play(animName);
}
}