I have a camera and when I press a button the camera plays an animation. After that the player can push again on a button and the camera should play another animation but from where the camera is located at that point. And not from where it was before the first animation.
So what I though I could do is:
1. Play the animation
2. wait till the end
3. Get the position and rotation
4. Stop Animation
5. Rewind animation to start frame
6. Set new position and rotation
If I Rewind and Stop that animation stays at its last frame instead of going back. And if I wait for next fixed update the camera is at the first frame of the animation. And if I then put the camera to its previous rotation and position, it works but you see it go back to the first frame and then back to new position. So you see the screen change twice.
Here is what I had:
protected override IEnumerator CameraAnim()
{
Camera.main.animation.Play(CameraAnimation.name);
yield return new WaitForSeconds(CameraAnimation.length);
Vector3 pos = Camera.main.transform.localPosition;
Quaternion rot = Camera.main.transform.rotation;
Debug.Log(pos);
Camera.main.animation.Rewind(CameraAnimation.name);
Camera.main.animation.Stop(CameraAnimation.name);
Camera.main.transform.localPosition = pos;
Camera.main.transform.rotation = rot;
Debug.Log(pos);
IsActive = true;
}