I have recently come to Unity from many years working with blender.
Im still new to Csharp, but i am really keen to learn it. Im trying to
use, if (Input.GetKeyDown( , To open my door when inside the trigger, but i get nothing but errors 
Any help would be appreciated. Thank you in advance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorScript : MonoBehaviour {
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
}
void OnTriggerEnter(Collider other)
{
anim.SetTrigger("OpenDoor");
}
void OnTriggerExit(Collider other)
{
anim.enabled = true;
}
void pauseAnimationEvent()
{
anim.enabled = false;
}
}
The errors will give you a clue to what is wrong. They give the line number and a description. It’s usually enough to figure it out, otherwise post the error with your code.
There is no error in this script, i need to add a input for a key press.
I need help where to implement it. Thank you
The quick and easy way is to check in OnTriggerStay, which is called every frame an object is in the trigger.
void OnTriggerStay (Collider col)
{
if (Input.GetKeyDown (KeyCode.Space))
{
// open your door here
}
}
Note that this would check for your input no mater which object is in the trigger, even an enemy. Add an additional check using col.CompareTag (“player”) to see if it is the player that is in the trigger.
Usually checking for player input is done on the player controller script. That way you can keep all your player input together, helping with more manageable code. In order to do this, you will need to pass a reference of the Door to the Player. On the Door, set a public bool canBeOpened to true when the player enters the trigger, and false when the player leaves the trigger, indicating when the door can be opened. Then in the Update method of your Player you could check for KeyDown, and open the door if the Door.canBeOpened is true, open it.
Thank you. So where about should i put that code into my current code.
I tried adding it, but it comes up indent error.
You would add it right after (or before) your OnTriggerEnter and Exit methods.
I’m not sure what you meant by an indent error, will it compile? Any console messages?