- Home /
Door opening doesn't open!
This script is supposed to open the door of outposts, but for some peculiar reason it isn't.
private var doorIsOpen : boolean = false; private var doorTimer : float = 0.0; private var currentDoor : GameObject;
var doorOpenTime : float = 3.0; var doorOpenSound : AudioClip; var doorShutSound : AudioClip;
function Update () { if(doorIsOpen) { doorTimer += Time.deltaTime; } if(doorTimer > doorOpenTime) { Door(doorShutSound,false,"dooropen",currentDoor); doorTimer = 0.0; } }
function OnControllerColliderHit(hit : ControllerColliderHit){ if(hit.gameObject.tag == "outpostDoor" && doorIsOpen == false) { var currentDoor : GameObject = hit.gameObject; Door(doorOpenSound,true,"dooropen",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)
Also, it isn't the sound and animation names, I've already checked them. Thanks
pleaseeeee put it in code format - no one will read it like this
It also might be a good idea to tell us what the script is suppose to do?
Answer by Bravini · Jan 23, 2011 at 07:26 PM
Please use the search before asking, this have been answered already http://answers.unity3d.com/questions/7023/open-and-close-a-door-with-a-keypress
Also, don't use curse words, this is an E rated site.
Answer by Mike 3 · Jan 23, 2011 at 07:29 PM
Looks like the Door call in update has the wrong animation name - it's got the dooropen animation instead of whatever the closing animation name should be ("doorclose" ?)
Also it's a little bit of an odd script - it only lets you open one door at any time, not sure if that's intentional or not
Your answer
Follow this Question
Related Questions
Always play music? 1 Answer
0xFEFF error im new PLEASSE help. Script error 1 Answer
Instantiate cloned prefab to local position of an empty object 1 Answer
Using a string in a C# script in a .js 1 Answer
Zombie Spawner script 2 Answers