change object rotation at runtime inside animation window

is it possible to change it at runtime when the game is running?

for example now it’s 15 at frame 10, change it to 25 ???

I dont fully understand. Yes, you can change an object’s rotation during runtime via code. And also yes, you can run a function using an event at a specific frame in an animation. But what are you trying to accomplish?

public void awd()
{

Keyframe[ ] keys;
keys = new Keyframe[3];
keys[0] = new Keyframe(0, 0);
keys[1] = new Keyframe(1, 5);
keys[2] = new Keyframe(2,0);

var curve = new AnimationCurve(keys);

clip.SetCurve(“wa”, typeof(Transform), “localPosition.x”, curve);

}

it’s working fine when i want to change object’s localPosition

but when i use this

clip.SetCurve(“wa”, typeof(Transform), “localRotation.z”, curve);

I just don’t know what happens

I simply want to change it’s rotation at keyFrame [1] :slight_smile:

Then just change the rotation during the animation itself. You shouldnt need any code. And if you do, then just have one animation for an “idle” state and then when the desired event/action occurs, have another animation where it goes to that rotation. That way the only code you will need is changing states.

1 Like

public AnimationClip clip;

void Update(){

if(Input.GetKeyDown(KeyCode.W)){

changeXPos();

}
if(Input.GetKeyDown(KeyCode.S)){

changeRot();

}

}

public void changeXPos()
{

Keyframe[ ] keys;
keys = new Keyframe[3];
keys[0] = new Keyframe(0,0);
keys[1] = new Keyframe(1,5);
keys[2] = new Keyframe(2,18);

var curve = new AnimationCurve(keys);

clip.SetCurve(“wa”, typeof(Transform), “localPosition.x”, curve);

}

public void changeRot()
{

Keyframe[ ] keys;
keys = new Keyframe[3];
keys[0] = new Keyframe(0,0);
keys[1] = new Keyframe(1,5);
keys[2] = new Keyframe(2,15);

var curve = new AnimationCurve(keys);

clip.SetCurve(“wa”, typeof(Transform), “localEulerAnglesRaw.z”, curve);

}