Set Z rotation according to Vector2

Hey all.
Let’s say I have a vector, for example Vector2(1, 0.5f) and I would like to set Z rotation of a Transform according to that vector. How can I achieve that?
Thank you.

where you able to find how? im faceing the same issue today, i have a vector2 for x and y. And want to use the angle between x and that vector to rotate my object around z axis

The solution :

  1. Get your Input X and Y.
  2. then convert it to rad
  3. convert this rad to deg
  4. (if you need an offset, do it here)
  5. Assign the result to Z Angle rotation

Code to convert

public Vector2 v2;
public float angle;
    
Void DoConversion()
    {
    float radvalue = Mathf.Atan2(v2.y,v2.x);
    angle= radvalue * (180/Mathf.PI);
    }