UNT0034 A Vector3 can be converted into a Vector2.

March 28, 2023 ยท View on GitHub

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.