Exemplo n.º 1
0
    /// <summary>
    /// Moves the transform by a clamped move from a reference point.
    /// </summary>
    /// <param name="transform"></param>
    /// <param name="bounds"></param>
    /// <param name="move"></param>
    public static void AttemptMoveInBounds(this Transform transform, Bounds bounds, Vector3 move, Vector3 reference)
    {
        Vector3 targetCenterPos = reference + move;

        Debug.DrawLine(reference, targetCenterPos, Color.magenta);

        Vector3 clampedTargetCenterPos = M_Math.ClampInBounds(targetCenterPos, bounds);

        Debug.DrawLine(targetCenterPos, clampedTargetCenterPos, Color.red);

        move = clampedTargetCenterPos - reference;

        //StartCoroutine(M_Math.ExecuteDelayed(0.05f, () => Debug.Break()));
        Debug.DrawRay(reference, move, Color.yellow);

        //   MDebug.Log(move);
        transform.Translate(move, Space.World);
    }