[Help]Snaping angles

Hi everyone
today all day i was trying to figure it out and i frustrated and decided to go here and ask some one for help.

So my problem is that i want to make object(cube) and rotate exactly 45 degrees and stay in 45 degrees (snap there)
for position it works simple just
"if (Input.GetKeyDown (“up”))

  • transform.position.y = 2;*"
    and it goes upward from 1 to 2 and stays there, i thought that whit rotation would be a simple as that but it doesn’t.
    I wrote this piece of code:
    var var rotationAmount = 45.0;
    *if (Input.GetKey (“right”)) *
    _ transform.Rotate (0, rotationAmount * Time.deltaTime, 0);_” but when i press button for split second or make getKeyDown it just start to act weird :roll:

So i want to know how to make object rotate from 0 degrees to 45 in y axis and snap to exact angle.

You could try setting

transform.eulerAngles.y = 45