Rotate a cloned object with key press

I’m trying to rotate a cloned object once it is spawned but i’m having difficulty and cant find any information about how to do this.

For example, i spawn a wall, once i press “R” it rotates to 90 degrees along its x axis. Or, if you press “R” it transforms to 90 and then you put it down? I just need an understanding on how to do this. I’m unfamiliar with Quaternions is this the problem?? The code i have doesn’t seem to be working.

        if (Input.GetMouseButtonDown(0))
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            // Storage point for the Ray
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
                // Assigning the point its variable
                endPoint = hit.point;

                GameObject clone;

                // Clone the objects and spawn them in the game 'world'
                clone = Instantiate(items_, endPoint, items*.transform.rotation) as GameObject;*_

if (Input.GetKey(KeyCode.R))
clone.transform.Rotate(0, 90, 0);
Debug.Log(“Rotating Object”);


As per your code the R key has to be pressed down in the same frame when the left mouse button is clicked.

Just take out the code that handles the R key press outside Mouse Button press check and change your code accordingly.

You need to declare your ‘clone’ gameobject to be outside Update in order for the object cloned to persist between multiple frame executions. Then on R keypress check if clone is null or not and if not null you can rotate it with the current rotation code. Also once the object is placed on the ground just set your clone object to null in order to avoid that object being rotated even after it is placed on the ground.