Can this be done ?

Hi, I think Mecanim has a big minus, what I do in script is make a variable called attackDistance then set it in the inspector depending on the type of enemy, and some times after testing I decide to change it, so I set up Mecanim and all works fine untill I decide to change the variable attackDistance in the inspector the I have to go into Mecanim and change the value in the picture below to match the variable attackDistance, wouldn’t it be a lot easier if I could assign a variable there that I could link to the variable attackDistance in script, am I missing something, is there another way, or can it not be done ?


You could always use only the Mecanim value by using Animator.Get/SetFloat() (or Integer if that’s what you’re using) in your script.

Maybe, instead, you could use a Mecanim parameter to keep track of state rather than distance. Perhaps an integer attackStyle instead of attackDistance, where attackStyle==0 might trigger a wrestling move, attackStyle==1 a punching move, attackStyle==2 a kicking move, and attackStyle==3 a ranged-distance move.

Then, in your script, when the character moves to whatever you define as punching range (perhaps a script variable value attackDistance around 10), you could call Animator.SetInteger(“attackStyle”, 1). This way, Mecanim doesn’t need to know what distance thresholds you’re currently using. It only knows that it’s time to do a punch.

In practice, the integers should really be constants or enums (e.g., enum AttackStyle { Grapple=0, Punch=1, etc. }).