Script/solution for manually changing % of animation through public float in viewport?
example: Two swinging axes copied through prefab, start swinging at the same position (0%), I need have control over their starting position manually visible in viewport. One start at 0% and need to make the other one to start at 25% while displaying the position in viewport.
Animation. I have reccomendations to use this:
https://docs.unity3d.com/ScriptReference/Animator.Play.html
But I have no really clue how as I am not programmer.
Answer by UnityCoach · Jan 23, 2017 at 11:31 PM
You may do something like this
void Start ()
{
GetComponent<Animator>().Play ("animation state name", 0, 0.25f);
}
Does not work, do I have to create some animation states before? All I need to do is written above in description. Animator controller name is: Axe_pivot and animation name is: Axe_swing
I simply need public float for moving animation base on % with displaying movement in viewport to sync it in level. Preferably linked to object as I might use it to many. and not saving to prefab.
If you could help i would be great. I suppose it it not that hard fo somebody who understand program$$anonymous$$g.
Yes, you do need to create animation states in the Animator Controller. Check the doc, it doesn't require more program$$anonymous$$g than the code I posted.
Simply create an Animator Controller, assign it to the Animator component on your object, then drag and drop the animations in the Animator Controller window, which will create states.
I dont really wanna create more states, but rather make my single animation adaptable by % start state. But ill look into this aswell. Thx.
Your answer
![](https://koobas.hobune.stream/wayback/20220612105356im_/https://answers.unity.com/themes/thub/images/avi.jpg)