Search Unity

How to save a change of Position/Rotation via script inside a animation outside runtime?

Discussion in 'Animation' started by nadin1223, Oct 9, 2020.

  1. nadin1223

    nadin1223

    Joined:
    Sep 10, 2020
    Posts:
    2
    Hi Guys,
    it is a Noob Questions. Also thanks a lot for any help!

    Scenario outside runtime:

    A have a cube. Cube has a animation control and a animation.
    All works fine in Animation Window.

    I create a small c#-Script to move my cube outside runtime. This works fine too.

    My opinion was, when a select in Animation Window "play the animation clip" and "enable keyframe recording mode" and start my script, that the moves from cube would be saved in animation.

    But my result is that my cube doesn´t move or it doesn´t save the keyframe. What is my mistake?
    Manuelly change of position/rotation works fine. But to change value inside script and save it inside a animation seems not to work... :(

    Unity 2019.4

    My C#-script:
    Code (CSharp):
    1. public class PosRotTest : MonoBehaviour
    2. {
    3. /*...*/
    4. private async void startMove(){
    5. transform.Translate(0.1f, 0, 0);
    6. /*...*/
    7. transform.rotation=new Quaternion(_rot[0], _rot[1], _rot[2], _rot[3]);
    8. /*...*/
    9. await Task.Delay(TimeSpan.FromSeconds(1));
    10. startMove();
    11. }
    12. }
    13.  

    Regards
    Nadin