Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Changing animation speed

Discussion in 'Scripting' started by Kjetil403, Jun 16, 2015.

  1. Kjetil403

    Kjetil403

    Joined:
    May 1, 2014
    Posts:
    3
    So I have a game object with the animation component attached, with one animation file. Everything runs smoothly. Now I want to change the speed of the animation, which I am having trouble with.
    The animation is marked as legacy. Here is my code:

    var animSpeed:Animation;

    animSpeed = GetComponent.<Animation>();

    animSpeed.speed = 5 //for instance


    I have also tried something like this:

    animation["animation_name"].speed = something;

    What am I doing wrong?
     
  2. TheForsaken95

    TheForsaken95

    Joined:
    Aug 29, 2014
    Posts:
    30
    Have you tried setting the animation speed to a value between 0 and 1? From my understanding, setting the speed to 0.5f would play the animation at half speed.
    Code (CSharp):
    1. animation["Animation name"].speed = 0.5f;
     
  3. Kjetil403

    Kjetil403

    Joined:
    May 1, 2014
    Posts:
    3
    Still no luck. I keep getting the error:
    Type 'UnityEngine.Component' does not support slicing.
     
  4. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
  5. Kjetil403

    Kjetil403

    Joined:
    May 1, 2014
    Posts:
    3
    Yes, that solved it! Thanks!