Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 731 Bytes

UNT0034.md

File metadata and controls

39 lines (30 loc) · 731 Bytes

UNT0034 A Vector3 can be converted into a Vector2.

A Vector3 can be converted into a Vector2. (The z is discarded).

Examples of patterns that are flagged by this analyzer

using UnityEngine;

class Camera : MonoBehaviour
{
    private void Update()
    {
        Vector3 v3 = ...;
        Vector2 v2 = ...;
        var distance = Vector2.Distance(v2, new Vector2(v3.x, v3.y));
    }
}

Solution

Use built-in conversion:

using UnityEngine;

class Camera : MonoBehaviour
{
    private void Update()
    {
        Vector3 v3 = ...;
        Vector2 v2 = ...;
        var distance = Vector2.Distance(v2, v3);
    }
}

A code fix is offered for this diagnostic to automatically apply this change.