Simple Mecanim coding tutorial

Someone please help me keep my sanity. It’s been Five days and I can’t find a simple tutorial to help me create the javascript (or and other code) for my animations. The tutorials I have found, are all from 2010 -20123 and I always receive error messages when I copy the code they’ve written.

Every video on Youtube and I’ve found online shows the pre-coding part of Mecanim (creating layers and/or masking layers), but no one has a simplified scripting tutorial.

Can anyone help me? I’ve attached what I have so far.


Here’s a tutorial from me (in C#). You might want to check the previous one too for the setup in the Animator.

Make sure you spell your parameters in the script the same as you have in the Animator, ie as speed and Direction

Also be sure to check out the documentation

http://docs.unity3d.com/Documentation/ScriptReference/Animator.html

The main methods you’ll need to familiarize yourself with are:

GetFloat
SetFloat
GetBool
SetBool
GetInteger
SetInteger

Some weeks ago I had the same problem.

http://video.unity3d.com/video/7362044/unity-40-mecanim-animation-tutorial helped me a lot.

On http://forum.unity3d.com/threads/159894-Mecanim-Unity-4-0-starter-tutorial there is also a thread about the tutorial and in one of the comments you can find a link to the complete project file of it.

Good luck.

Agreed, I wouldn’t be able to do anything with Mecanim without that tutorial.

I notice in your blend tree that you’ve got speed controlling the direction of the run. Surely that should be Direction (in the Inspector)

I’m also looking for a simple tutorial on this subject. Just showing how to start coding the playerscript from the ground up going from idle animation to running animation through player input. Most I found use the script that came with the Mecanim tutorial. While that works I would like to know how to create it myself step by step so I can understand it a lot better.

My two are pretty simple
The Animator
The Script

I should say that I imported my character with a generic rig, not a humanoid rig, as I had already created the animations in my modelling software.

Thank you so much, your script worked.

I had to add a “;” to the c# because I was getting the “error cs1525, unexpected Symbol”.

My character can now move according to what direction I press. I can finally sleep easy tonight :smile: