How to set priority over certain actions?

Hello. So I have things in my game for my NPC AI that I’ve been thinking of as actions, but it is basically a large chunk of code in a method known as something like “Find Food” or “Run From Enemy”. Obviously running from an enemy is far more important than finding food, and the NPC can only focus on one of these at a time, so how do I give an action such as that a priority over other less helpful actions? Of course, I could do something such as the code below, but that looks like a horrible way to do it and I’d have to modify all the code everytime I add a new action for the NPC to take.

//Bad looking way for letting the NPC choose which action to take.

if (Enemy != null){
EvadeEnemy ();
} else{
FindFood ();
}

Hmm, How about creating an another method that manages the current ‘state’ of the AI?
In there your AI can evaluate the current situation and can decide wether runaway from an Enemy or FindFood. Also a Mecanim(AnimatorController) can be used to implement the AI state.

The way you implemented above can cause ‘jitter’ on the boundary condition, and not extendable, either.