How do I tell an object to only interact with an object only on a specific animation?

as the title says, I have a variable set that if true the object will be set to animation 2, problem is how do I interact with this object only when its on this specific animation?

condition:
object 1 distance to object 2 is below x pixels
e key is pressed

action:
set object 2 animation to animation 1