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);
}
}
Please format your code by highlighting it and clicking the 101/010 button - I've done it for you this time, but when this is performed after the question is posted symbols are escaped
– whydoidoitDo you have a collider attached to the door?
– whydoidoitoh, I just formatted too, sorry. As it's C#, it's all yours =] I would suggest to @sshockrat to place this debug after the
– AlucardJayif (Physics.RayCast ....to check if there is a collider and if it is tagged correctly (as Mike suggested). Debug.Log("raycast hit tag : " + hit.collider.gameObject.tag);I see you did the decent job of unescaping the symbols though :)
– whydoidoitIm sorry for the question format. This is my first question in Unity Answers. So i placed debug line and here what the console shows raycast hit tag : playerDoor UnityEngine.Debug:Log(Object) PlayerCollisions:Update() (at Assets/Scripts/PlayerCollisions.cs:21)
– sshockrat