Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

30/8/2021 Unity - Scripting API: Transform.

Rotate

unity.com

Search scripting...
TextGenerator
TextMesh
Texture
Manual Transform.Rotate
Scripting API

Leave feedback
Texture2D
Version: 2020.3 C#
Texture2DArray SWITCH TO MANUAL

Texture3D
Time
Description
Touch
Use Transform.Rotate to rotate GameObjects in a
TouchScreenKeyboard
variety of ways. The rotation is often provided as
TrailRenderer an Euler angle and not a Quaternion.
Transform
You can specify a rotation in world axes or local
Tree
axes.

TreeInstance
TreePrototype World axis rotation uses the coordinate system of
UICharInfo the Scene , so when you start rotate a GameObject,
its x, y, and z axes are aligned with the x, y, and z
UILineInfo
world axes. So if you rotate a cube in world space,
UIVertex its axes align with the world. When you select a
Vector2 cube in the Unity Editor’s Scene view, rotation
Vector2Int Gizmos appear for the left/right, up/down and
forward/back rotation axes. Moving these Gizmos
Vector3
rotates the cube around the axes. If you de-select
Vector3Int and then re-select the cube, the axes restart in
Vector4 world alignment.

WaitForEndOfFrame
Local rotation uses the coordinate system of the
WaitForFixedUpdate
GameObject itself. So, a newly created cube uses
WaitForSeconds its x, y, and z axis set to zero rotation. Rotating the
cube updates the rotation axes. If you de-select
and the re-select the cube, the axes are shown in
the same orientation as before.

A cube not rotated in Local Gizmo Toggle

https://docs.unity3d.com/ScriptReference/Transform.Rotate.html 1/7
30/8/2021 Unity - Scripting API: Transform.Rotate

unity.com

Search scripting...
TextGenerator
TextMesh Manual Scripting API
Texture
Texture2D
Version: 2020.3 C#
A cube rotated in Local Gizmo Toggle

Texture2DArray
Texture3D
Time
Touch
TouchScreenKeyboard
TrailRenderer
Transform
Tree
TreeInstance A cube not rotated in Global Gizmo Toggle

TreePrototype
UICharInfo
UILineInfo
UIVertex
Vector2
Vector2Int
Vector3
Vector3Int
A cube rotated in Global Gizmo Toggle

Vector4
WaitForEndOfFrame
WaitForFixedUpdate For more information on Rotation in Unity, see
WaitForSeconds Rotation and Orientation in Unity.

Declaration
public void Rotate(Vector3 eulers,
Space relativeTo
= Space.Self);

Parameters
eulers The rotation to apply in euler
angles.

relativeTo Determines whether to rotate the


GameObject either locally to the

https://docs.unity3d.com/ScriptReference/Transform.Rotate.html 2/7
30/8/2021 Unity - Scripting API: Transform.Rotate

GameObject or relative to the


unity.com
Scene in world space.

Search scripting... Description


TextGenerator Applies a rotation of eulerAngles.z degrees around
TextMesh Manual theScripting
z-axis, eulerAngles.x
API degrees around the x-axis,
Texture and eulerAngles.y degrees around the y-axis (in
that order).
Texture2D
Version: 2020.3 C#
Texture2DArray Rotate takes a Vector3 argument as an Euler
Texture3D angle. The second argument is the rotation axes,
which can be set to local axis (Space.Self) or
Time
global axis (Space.World). The rotation is by the
Touch
Euler amount.
TouchScreenKeyboard
TrailRenderer
Transform Declaration
Tree
public void Rotate(float xAngle,
float yAngle,
float
TreeInstance zAngle,
Space relativeTo = Space.Self);
TreePrototype
UICharInfo
Parameters
UILineInfo
UIVertex relativeTo Determines whether to rotate the
Vector2 GameObject either locally to the
GameObject or relative to the
Vector2Int
Scene in world space.
Vector3
xAngle Degrees to rotate the GameObject
Vector3Int
around the X axis.
Vector4
yAngle Degrees to rotate the GameObject
WaitForEndOfFrame
around the Y axis.
WaitForFixedUpdate
zAngle Degrees to rotate the GameObject
WaitForSeconds
around the Z axis.

Description
The implementation of this method applies a
rotation of zAngle degrees around the z axis,
xAngle degrees around the x axis, and yAngle
degrees around the y axis (in that order).

Rotate can have the euler angle specified in 3


floats for x, y, and z.

The example shows two cubes: one cube uses


Space.Self (the local space and axes of the
GameObject) and the other uses Space.World (the
https://docs.unity3d.com/ScriptReference/Transform.Rotate.html 3/7
30/8/2021 Unity - Scripting API: Transform.Rotate

space and axes in relation to the /Scene/). They


unity.com
are both first rotated 90 in the X axis so they are
not aligned with the world axis by default. Use the
Search scripting... xAngle, yAngle and zAngle values exposed in the
inspector to see how different rotation values
TextGenerator
apply to both cubes. You might notice the way the
TextMesh Manual cubes
Scripting
visuallyAPI
rotate is dependant on the current
Texture orientation and Space option used. Play around
Texture2D with the values while selecting the cubes in the
Version: 2020.3 C#
scene view to try to understand how the values
Texture2DArray
interact.
Texture3D
Time
using UnityEngine;

Touch
TouchScreenKeyboard // Transform.Rotate example

TrailRenderer //

Transform // This script creates two different


// Add it onto any GameObject in a s
Tree
TreeInstance public class ExampleScript : MonoBeh
TreePrototype {

UICharInfo public float xAngle, yAngle, zAn

UILineInfo
private GameObject cube1, cube2;
UIVertex
Vector2 void Awake()

Vector2Int {

cube1 = GameObject.CreatePri
Vector3
cube1.transform.position = n
Vector3Int
cube1.transform.Rotate(90.0f
Vector4 cube1.GetComponent<Renderer>
WaitForEndOfFrame cube1.name = "Self";

WaitForFixedUpdate
cube2 = GameObject.CreatePri
WaitForSeconds
cube2.transform.position = n
cube2.transform.Rotate(90.0f
cube2.GetComponent<Renderer>
cube2.name = "World";

void Update()

cube1.transform.Rotate(xAngl
cube2.transform.Rotate(xAngl
}

https://docs.unity3d.com/ScriptReference/Transform.Rotate.html 4/7
30/8/2021 Unity - Scripting API: Transform.Rotate

unity.com
Declaration
Search scripting... public void Rotate(Vector3 axis,
float angle,
Space
TextGenerator relativeTo = Space.Self);

TextMesh Manual Scripting API


Texture Parameters
Texture2D
Version: 2020.3 C#
angle The degrees of rotation to apply.
Texture2DArray
Texture3D axis The axis to apply rotation to.

Time relativeTo Determines whether to rotate the


Touch GameObject either locally to the
GameObject or relative to the
TouchScreenKeyboard
Scene in world space.
TrailRenderer
Transform
Description
Tree
Rotates the object around the given axis by the
TreeInstance
number of degrees defined by the given angle.
TreePrototype
UICharInfo Rotate has an axis, angle and the local or global
parameters. The rotation axis can be in any
UILineInfo
direction.
UIVertex
Vector2
Vector2Int Declaration
Vector3
public void Rotate(Vector3 eulers);
Vector3Int
Vector4
WaitForEndOfFrame Parameters
WaitForFixedUpdate
eulers The rotation to apply in euler angles.
WaitForSeconds

Description
Applies a rotation of eulerAngles.z degrees around
the z-axis, eulerAngles.x degrees around the x-axis,
and eulerAngles.y degrees around the y-axis (in
that order).

The rotation is relative to the GameObject's local


space (Space.Self).

Declaration

https://docs.unity3d.com/ScriptReference/Transform.Rotate.html 5/7
30/8/2021 Unity - Scripting API: Transform.Rotate

public void Rotate(float xAngle,


float yAngle,
float
zAngle); unity.com

Search scripting...
TextGenerator
Parameters
TextMesh Manual xAngle
ScriptingDegrees
API to rotate the GameObject
Texture around the X axis.

Texture2D
Version: 2020.3 yAngle Degrees to rotate the GameObject C#
Texture2DArray around the Y axis.

Texture3D zAngle Degrees to rotate the GameObject


Time around the Z axis.
Touch
TouchScreenKeyboard Description
TrailRenderer The implementation of this method applies a
Transform rotation of zAngle degrees around the z axis,
xAngle degrees around the x axis, and yAngle
Tree
degrees around the y axis (in that order).
TreeInstance
TreePrototype The rotation is relative to the GameObject's local
space (Space.Self).
UICharInfo
UILineInfo
UIVertex
Declaration
Vector2
public void Rotate(Vector3 axis,
float angle);
Vector2Int
Vector3
Vector3Int Parameters
Vector4
axis The axis to apply rotation to.
WaitForEndOfFrame
WaitForFixedUpdate angle The degrees of rotation to apply.

WaitForSeconds
Description
Rotates the object around the given axis by the
number of degrees defined by the given angle.

Rotate has an axis, angle and the local or global


parameters. The rotation axis can be in any
direction.
The rotation is relative to the
GameObject's local space (Space.Self).

Did you find this page useful? Please give it


a rating:

https://docs.unity3d.com/ScriptReference/Transform.Rotate.html 6/7
30/8/2021 Unity - Scripting API: Transform.Rotate

Report a problem on this page unity.com

Search scripting...
TextGenerator
TextMesh Manual Scripting API
Texture
Texture2D
Version: 2020.3 Is something described here not working as you expect it to?C#
It

Texture2DArray
might be a Known Issue. Please check with the Issue Tracker
Texture3D
Time at issuetracker.unity3d.com .

Touch
TouchScreenKeyboard Copyright ©2021 Unity Technologies. Publication Date:
TrailRenderer
Transform 2021-08-23.

Tree
Tutorials
Community Answers
Knowledge
TreeInstance
TreePrototype Base
Forums
Asset Store

UICharInfo
UILineInfo
UIVertex
Vector2
Vector2Int
Vector3
Vector3Int
Vector4
WaitForEndOfFrame
WaitForFixedUpdate
WaitForSeconds

https://docs.unity3d.com/ScriptReference/Transform.Rotate.html 7/7

You might also like