Rewind
Rewinds all animations.
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.AnimationModule
Rewind()
Rewinds all animations.
public void Rewind()
Remarks
Sets the time of all animations to 0.
Additional Resources: _time
Rewind(string)
Rewinds the animation named .
namepublic void Rewind(string name)
Parameters
The name of the animation to rewind.
Remarks
Sets the time of the animation named to 0. If there is no animation named , nothing happens.
namenameAdditional Resources: _time
Examples
using UnityEngine;[RequireComponent(typeof(Animation))]public class AnimationRewindExample : MonoBehaviour{ public AnimationClip walkClip; Animation m_Animation; void Start() { m_Animation = GetComponent<Animation>(); if (walkClip != null) { m_Animation.AddClip(walkClip, "Walk"); m_Animation.Play("Walk"); } } private void Update() { if (m_Animation.IsPlaying("Walk")) { // This printed value increases with each Update because the clip is playing. Debug.Log($"Walk state time: {m_Animation["Walk"].time}."); if (Input.GetKeyDown(KeyCode.R)) { m_Animation.Rewind("Walk"); // The new state time will be 0. Debug.Log($"Walk state time: {m_Animation["Walk"].time}."); } } }}