Hi guys! So, I’m working on a college assignment, and for it I have to have 10 interactable objects in a scene. What I was wondering is, how would I go about making it so that an animation plays when the player is inside a trigger and pressing a key? I have some code here that returns no errors but doesn’t seem to work either:
void Start()
{
boardAnim = GetComponentInChildren<Animator>();
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player" && Input.GetKeyDown("space"))
{
boardAnim.SetTrigger("isOpening");
print("key pressed");
}
}
(Had to cut the boardAnim initialization and a bracket at the end for formatting purposes)
Any help with this would be appreciated!