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

Script not reversing animation.

Discussion in 'Scripting' started by cristo, Nov 8, 2015.

  1. cristo

    cristo

    Joined:
    Dec 31, 2013
    Posts:
    265
    Hi, just trying to create a small script reversing the animation on an object. No errors are popping up, but it just makes the animation loop and not reverse.

    Any feedback would be great.



    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class reverseAnim : MonoBehaviour {
    5.     public GameObject clothtest2;
    6.  
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.      
    11.    
    12.     }
    13.    
    14.     // Update is called once per frame
    15.     void Update () {
    16.         clothtest2.GetComponent<Animation>().Play("Take 001");
    17.         speed = -1.0f; ;
    18.      
    19.     }
    20. }
    21.  
     
  2. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    You haven't set the time of the animation to be at the end, therefore it appears that you are trying to go backwards from 0.

    Try using (with the appropriate beginning sections :
    Code (CSharp):
    1. .time = .length
     
    cristo likes this.
  3. cristo

    cristo

    Joined:
    Dec 31, 2013
    Posts:
    265
    Thanks for the feedback.