- Home /
Question by
robounited · Feb 22, 2013 at 04:43 PM ·
errordoor
Input Key Named: Enter is unknown error, Door open on keydown
Hi guys, I have a javascript to open a door when i collide with it. I changed the code so it only opens when i press enter but im getting an error saying "Input Key Named: Enter is unknown". Can someone help me work out where i have gone wrong and how to fix it. thanks
code:
private var doorIsOpen : boolean = false;
private var doorTimer : float = 0.0;
private var currentDoor : GameObject;
var doorOpenTime : float = 3.0;
var doorOpenSound : AudioClip;
var doorCloseSound : AudioClip;
var menu_beep : AudioClip;
function Update(){
if(doorIsOpen){
doorTimer += Time.deltaTime;
if(doorTimer > 3){
Door(doorCloseSound, false, "doorshut", currentDoor);
doorTimer = 0.0;
}
}
}
function OnTriggerEnter(collisionInfo : Collider){
if(collisionInfo.gameObject.tag == "Key"){
audio.PlayOneShot(menu_beep);
Destroy(collisionInfo.gameObject);
achievementManagementScript.pickedUpKey();
}
}
function OnControllerColliderHit(hit : ControllerColliderHit){
if (hit.gameObject.tag == "Door" && doorIsOpen == false && Input.GetKeyDown("Enter")){
currentDoor = hit.gameObject;
Door(doorOpenSound, true, "dooropen", currentDoor);
}
}
function Door(aClip : AudioClip, openCheck : boolean, animName : String, thisDoor : GameObject){
audio.PlayOneShot(aClip);
doorIsOpen = openCheck;
thisDoor.animation.Play(animName);
}
@script RequireComponent(AudioSource)
Comment
Best Answer
Answer by AutoFredrik · Feb 24, 2013 at 11:25 AM
You can't find a key by it's name that way in unity. That's when you use buttons in the input manager you need to use keycode:
if(Input.GetKeyDown(Keycode.Enter))
That should work.