Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    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.
     
unityunity