Rotate and obejct with Key

looking to try and rotate and object in one axis with a key press and am not able to wrap my head around how this works.

What I am trying to do. have it so the player hits the r key and the object rotates in the Yaxis 90%.

I had this working at one point but it wasn’t smooth. so i looked into making a smooth motion (through a jason Weimenn

) I understand how that works.

But what I think I need to be able to do is get just the X and Z axis of the object have it stay put and then move it 90 on the y. but i cant figure out how to extract and axis rotation.

any help would be appreciated thanks!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Tile : MonoBehaviour
{
    private Transform startRotPos;
    private Transform endRotPos;

    private float rotAmount = 90f;

    [SerializeField] [Range(0f, 1f)]
    float lerpPct;

    void Update()
    {
        endRotPos.rotation = Quaternion.Euler(Input.GetAxis("startRotXPos"), rotAmount, Input.GetAxis("startRotZPos"));
 
        if (Input.GetKeyDown("r"))
        {
            transform.position = Vector3.Lerp(startRotPos.position, endRotPos.position, lerpPct);
            transform.rotation = Quaternion.Lerp(startRotPos.rotation, endRotPos.rotation, lerpPct);

        }
    }
}

The best way to precisely control only one axis of rotation is to put extra GameObjects into your hierarchy, and then each one pivots only one axis, and you directly control it.

For instance, the deck gun on a battleship might look like this:

5824186--617248--Screen Shot 2020-05-08 at 8.22.22 PM.png

Once you have a barebones setup like the above and scripts to drive it, then you can go back and “hang” any random geometry on any of the given parts: the turret, the barrels, etc.

Thanks for the reply. I’m not sure what you mean by offset of y in your example?

Also I am having issues understanding when to use rotate rotation get axis or any of these. When I ghink I have an idea and try it i get a “blah blah can’t be used as a method”. So I bel8ve i need to know how to get just one axisbof an object?