- Home /
Unity Game Design Function Door, Not Opening. Help Please?
So i've ran through my code almost like 20 times and cannot see any problems in it, can maybe one of you can point it out to me?
Cheers..
private var doorIsOpen : boolean = false;
private var doorTime : float = 0.0;
private var currentDoor : GameObject;
var doorOpenTime : float = 3.0;
var doorOpenSound : AudioClip;
var doorShutSound : AudioClip;
var doorTimer : float = 0.0;
var myOutpost : GameObject;
function Start () {
doorIsOpen = false;
}
function Update () {
}
function OnControllerColliderHit (hit : ControllerColliderHit){
Debug.Log(hit.transform.name + "hgf");
// This is where it is checking if it is colliding.
if(hit.gameObject.tag == "Door" && doorIsOpen == false){
currentDoor = hit.gameObject;
Door(doorOpenSound, true, "dooropen", currentDoor);
audio.PlayOneShot(doorOpenSound);
doorIsOpen = true;
myOutpost = GameObject.Find("OutpostMain");
myOutpost.animation.Play("dooropen");}
if(doorIsOpen){
doorTimer += Time.deltaTime;
if(doorTimer >= doorOpenTime){
ShutDoor();
doorTimer = 0.0;
}
}
}
// This function is called when the door needs to closes
function ShutDoor(){
audio.PlayOneShot(doorShutSound);
doorIsOpen = false;
//myOutpost = GameObject.find("outpost");
myOutpost.animation.Play("doorshut");
Door(doorShutSound, false, "doorshut", currentDoor);
}
function Door(aClip : AudioClip, openCheck : boolean, animName : String, thisDoor : GameObject){
audio.PlayOneShot(aClip);
doorIsOpen = openCheck;
thisDoor.transform.parent.animation.Play(animName);
}
@script RequireComponent(AudioSource)
Comment
Nothing's jump out at me; on 55 just before the Play(animName) put a Debug.Log in there to ensure you are getting to that. I'm assu$$anonymous$$g thisDoor.transform.parent is Outpost$$anonymous$$ain or in any case the parent does actually have an animation named 'dooropen'?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Open door on input key 1 Answer
Need help with door opening and closing script/animation 3 Answers
Openable door help 1 Answer
Semicolon problem melee. 1 Answer