# matrix

> Sets the Matrix4x4 that the Unity Editor uses to draw Gizmos.

## Definition

* **Type:** Property
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public static Matrix4x4 matrix { get; set; }
```

### Remarks

The [Gizmos.matrix](/engine/6000.7/script-reference/unityengine/gizmos/matrix.md) stores the position, rotation and scale of the [Gizmos](/engine/6000.7/script-reference/unityengine/gizmos.md). By default, [Gizmos](/engine/6000.7/script-reference/unityengine/gizmos.md) always uses world coordinates. The default [Gizmos.matrix](/engine/6000.7/script-reference/unityengine/gizmos/matrix.md) transforms the world coordinates using a default identity matrix. [Transform.localToWorldMatrix](/engine/6000.7/script-reference/unityengine/transform/localtoworldmatrix.md) changes local coordinate space to world space.

[GameObject](/engine/6000.7/script-reference/unityengine/gameobject.md)s often use local coordinates. [Gizmos.matrix](/engine/6000.7/script-reference/unityengine/gizmos/matrix.md) changes these local coordinates into world coordinates to allow [Gizmos](/engine/6000.7/script-reference/unityengine/gizmos.md) to use them.  For example, a rotating object uses local coordinates.  A transfer into world coordinates happens using [Gizmos.matrix](/engine/6000.7/script-reference/unityengine/gizmos/matrix.md). To visualise the  object, use [Gizmos.DrawCube](/engine/6000.7/script-reference/unityengine/gizmos/drawcube.md). See below.

To use the example to draw a red, semi-transparent, cube gizmo:

1. Place this example script on a Cylinder at the origin.

2. Select the Cylinder in the Hierarchy and then click the `Play` button.

3. Next, click the `Scene` button. The gizmo should appear.

The cylinder will rotate in `Play` mode and be seen rotating in `Scene` view.

### Examples

```csharp
using UnityEngine;

public class GizmosExample : MonoBehaviour
{
    public float rotationSpeed = 50.0f;

    void OnDrawGizmosSelected()
    {
        Gizmos.color = new Color(0.75f, 0.0f, 0.0f, 0.75f);

        // Convert the local coordinate values into world
        // coordinates for the matrix transformation.
        Gizmos.matrix = transform.localToWorldMatrix;
        Gizmos.DrawCube(Vector3.zero, Vector3.one);
    }

    // Rotate the cube.
    void Update()
    {
        float zRot = rotationSpeed * Time.deltaTime;
        transform.Rotate(0.0f, 0.0f, zRot);
    }
}
```
