So I have been doing this for a few days now, had problems with a script and been fixing stuff, now I encountered a problem that I dont know how to fix. When I open a door, script that is on that door checks if its closed, if it is closed it sets boolean to true when door open animation is played, same goes if the door is open, it sets boolean to false when door close animation is played. Now, I have this script, and what is not working is closing the door. It wont eve play the Debug.Log and I dont know why is that.
#pragma strict
var doorOpenSound : AudioClip[];
var doorCloseSound : AudioClip[];
var rayLenght = 10;
function Update(){
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Input.GetButtonDown("Interaction")){
if(Physics.Raycast(transform.position, fwd, hit, rayLenght)){
if(hit.collider.gameObject.tag == "DoorDefault"){
var checkDoorObject = hit.collider.GetComponent.<object_door_check_open>();
if(checkDoorObject.isOpen == false){
hit.collider.GetComponent(Animation).Play("door_wood_open");
Debug.Log("Opened the door");
GetComponent.<AudioSource>().PlayOneShot(doorOpenSound[Random.Range (0, doorOpenSound.length)]);
GetComponent.<AudioSource>().Play();
}
}
}
}
else if(Input.GetButtonDown("Interaction")){
Debug.Log("Trying to close the door!");
if(Physics.Raycast(transform.position, fwd, hit, rayLenght)){
if(hit.collider.gameObject.tag == "DoorDefault"){
if(checkDoorObject.isOpen == true){
hit.collider.GetComponent(Animation).Play("door_wood_close");
GetComponent.<AudioSource>().PlayOneShot(doorCloseSound[Random.Range (0, doorOpenSound.length)]);
GetComponent.<AudioSource>().Play();
}
}
}
}
}
** I have a feeling its a GetButtonDown problem, I dont know why would it open a door and it wont close. I have Interaction input with keycode E *