Question by
mohankhatri2 · Sep 16, 2016 at 07:42 AM ·
c#unity5
change the speed of animation during runtime in unity c#
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.
Comment