I want the script for the elevator door
In this script you can send a trigger to the animator when the gameObject named “ElevatorGameObject” is inside the collider and you press the keyboard letter “E”
void Start()
{
if(animator == null)
{
animator = GetComponent<Animator>();
if(animator == null)
{
Debug.LogError("No animator component on this script!",gameObject);
}
}
}
void OnTriggerEnter(Collider triggerInfo)
{
if(triggerInfo.gameObject.name("ElevatorGameObjectName") && Input.GetKey(KeyCode.E))
{
//open elevator door
animator.SetTrigger(onTriggerEnterParameterName);
}
}
void OnTriggerExit(Collider triggerInfo)
{
// do something else when exit
}
}
We use the “triggerInfo” variable to store the trigger information so we can acces the gameObject properties, in this case we acces the name and compare it. we also use the “&&” operator as a condicion for also havin the letter E pressed
I would use something like this
void OnCollisionStay (Collions col)
{
if (col.other == elevator)
{
if (Button pressed)
{
//open elevator
}
}
}
so just if your player it colliding with the elevator and he presses the button it should open.
Note: This code isn’t perfect its just an exampe of how you could do it