- Home /
I'm having a problem with getting a door to open
Here's a link to a video(skip 5 seconds)
CODE:
var liukuoviClip : AnimationClip;
private var Door = false;
function Update () {
if (Input.GetKeyDown(KeyCode.E) && Door == true)
{
GameObject.Find("liukuovi").GetComponent.().Play("liukuvaovi");
}
}
function OnTriggerEnter (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
Door = true;
}
}
function OnTriggerExit (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
Door = false;
}
}
Answer by connorwforman · Oct 19, 2017 at 03:20 PM
I don't know javascript, but I would try something like this:
on the door gameobject, check the "isTrigger".
make sure that your player's name in the Hierarchy is "Player"
Go to Edit>Player Input> make a new one by changing the number of inputs. Title it "Action", and make the positive button 'e'. This may even fix the problem entirely. Change the
KeyCode.E
to "Action". If this fixes it, ignore everything else.Attach this script to the door:
TIPS: If there is any error in the script, find the line that has the error. If the line with the error has one "=" add another one after it. If it has two, remove one.
using UnityEngine;
using SystemCollections;
public class doorOpen : Monobehaviour {
public AnimationClip liukuoviClip;
private bool isOpen = false;
void Start () {
}
void Update () {
if (isOpen == true) {
liukuoviClip.Play();
}
}
void OnTriggerStay (Collider other) {
if (other.gameObject.name == "Player") {
if (Input.GetButtonDown("Action")) {
isOpen = true;
}
}
}
}
So lets say that there is an error on isOpen = true;
, change it to isOpen == true;
.
If there is an error on line 15, or if (isOpen == true)
change it to if(IsOpen = true)
Your answer

Follow this Question
Related Questions
Door Script compiler error 0 Answers
How can I control each door lock state individual and also to control all the doors lock states ? 0 Answers
Problem with a Unity Scripting example from the scripting manual! 0 Answers
Reference DLL's 1 Answer
How to rotate spine by the script, while an animation from the animator is playing? 0 Answers