Animations can be confusing when scripting with Unity. One possible way to go about this is to use a variable, then enable that via script.
On your Mario player, place an Animator. Then, right click in your project pane and select Create > Animator Controller. Then under your Animator component on your Mario character, place the Animator Controller under the ‘Runtime Animator Controller’ blank. Now, double click on the Animator Controller in the project pane. A 2D grid should pop up (If not, add a new Animation tab). Now on your Mario character, if you imported animations, all the animations you want should also be under your project pane. Go ahead and drag them into the Animation pane that popped up (It should become orange). Now, right click on the Blue “Any State” button and select Make Transition. Then, click on your orange animation. There should now be an arrow connecting the blue to the red. Now, you can create a variable you can control from scripting. Click on the + by Parameters in the bottom left corner of the Animation pane and select bool. For example, you can rename it to runAnimation. Now, in the inspector, you should see something titled like ‘Any State → Base Layer.[animation name]’. Click on it. Now you should see a Conditions selection at the bottom. Change that to your runAnimation that we created a minute ago and make sure it’s set to ‘true’ to the right of that. Now any time that variable/parameter is set to true, it will play your animation. And the great thing about this is that since you’re using Unity’s animation system, you can use transitions. So if your ‘Any State’ animation is nothing, and you go into your run animation, there is a nice transition between the two (which you can change in the same window where you changed the condition to runAnimation). You can also make a smooth transition to another animation (or even another transition going from runAnimation to AnyState) by right clicking on runAnimation in the Animation pane and clicking on AnyState to create another arrow. There is a lot of customizable options you can do with this system, and with the Animator controller, you can use many many animtions (hundreds I guess?) with different ‘conditions’ from bools to ints to floats which you can all change from script! You can also grab the animator controller component instead of placing it in the blank on your Mario GameObject.
To change the parameter to false or true via script, use something like:
Animator marioAnimator;
Then under your start function:
marioAnimator = gameObject.GetComponent<Animator>();
When you want to set it to true/false:
marioAnimator.SetBool("runAnimation", [true/false]);
You can also use SetFloat, SetInt, etc.
I apologize for the lengthy message, but I hope this will steer you in the right direction. Also mess around with the options in the inspector to see what you can come up with and what you can learn.
You can also see in the Animator Controller in the Animator pane in Play mode when you set the bool to true/false, you will see the transition happen with a loading bar to show the time the animation is in its current state to show you that it’s playing (Which can also help you debug).
There are countless errors in this answer, and I apologize. I hope I’ve given you something to think about though (Feel free to correct my errors anyone).