I want to change the speed of animation to my desired speed during runtime of a program. I have an c# script and animator controller attached to the game object. The default speed of animation in unity is 1. I set the default speed value of animation to 0.3f. And during runtime of program, I want the speed of animation to 1.
using UnityEngine;
using System.Collections;
public class wowBoard : MonoBehaviour {
[SerializeField]
Animator anim;
bool changeSpeed;
void Start()
{
anim=GetComponent<Animator>();
playAnim();
changeSpeed=false;
}
public void playAnim()
{
anim.SetBool("show",true);
}
void Update()
{
if(changeSpeed)
playChangeSpeedAnim();
}
public void playChangeSpeedAnim()
{
anim.speed=1;
anim.SetBool("show",true);
}
}
The speed of animation did not get change to 1 even boolean value of changeSpeed is true.
To manipulate the animation speed you can use the Speed multiplier parameter field in the animation properties. If you select the animation in the animator, you will see in the inspector this: If you click on the "Parameter" checkbox, the Multiplier option will be enabled.
First, open the state machine associated with this animator by double-clicking on the controller field of your object. Then select the animation you would want to slow down in the state machine. Then in Inspector panel there is a speed field. You can just decrease its value to slow the animation down.
To manipulate the animation speed you can use the Speed multiplier parameter field in the animation properties.
If you select the animation in the animator, you will see in the inspector this:
If you click on the "Parameter" checkbox, the Multiplier option will be enabled. In the Multiplier field, you can select a float type parameter, and the animation speed will be set the parameter's value.
So, you can just create a new float parameter named speed
, and change the speed of the animation to X through script by just executing anim.SetFloat("speed", X);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With