unity tansform.rotate
时间: 2024-05-03 08:22:26 浏览: 100
Unity's Transform.Rotate method is used to rotate a GameObject around its own axis or a specific point in space.
Syntax:
```
public void Rotate(Vector3 eulerAngles, Space relativeTo = Space.Self);
```
Parameters:
- eulerAngles: The amount of rotation to be applied in degrees as a Vector3.
- relativeTo: Specifies whether the rotation is relative to the GameObject's own axis or the world axis. Default is Space.Self.
Example usage:
```
// Rotate the GameObject around its own y-axis by 45 degrees
transform.Rotate(new Vector3(0, 45, 0));
// Rotate the GameObject around the world y-axis by 90 degrees
transform.Rotate(new Vector3(0, 90, 0), Space.World);
```
Note: The Rotate method modifies the GameObject's Transform component, which affects the position, rotation, and scale of the GameObject. It is important to use this method carefully and avoid unexpected behavior.
阅读全文