UV mapping icosphere

I’m creating an Icosphere with a script, it generates the sphere perfectly but i’m having trouble UV mapping it.
Using this code for the mapping

Vector2[] uvs = new Vector2[mesh.vertices.Length];

for (int i = 0; i < mesh.vertices.Length; i++) {
       
uvs [i] = new Vector2 ((Mathf.Atan2 (mesh.vertices [i].z, mesh.vertices [i].x) / Mathf.PI / 2), (Mathf.Acos (mesh.vertices [i].y / radius) / Mathf.PI));

}

I get an Icosphere that looks like this


I’m not sure how to go about this.

That line happens because theres no UV seam, the last batch of triangles loops back from a high uv value to zero, duplicate the verts along the seam so you can have 2 uv coords in the same spot

@hpjohn I am facing that exact same problem and to avoid duplicating the question I will first try asking you here directly (also bumping this question in the process). Your conceptual explanation is good, however I am finding it difficult to implement a proper solution to that.

My current code is slightly different from the OP:

     Vector3[] nVertices = mesh.vertices;
        Vector2[] UVs = new Vector2[nVertices.Length];

        for (var i = 0; i < nVertices.Length; i++)
        {
            var unitVector = nVertices[i].normalized;
            Vector2 ISOuv = new Vector2(0, 0);
            ISOuv.x = (Mathf.Atan2(unitVector.x, unitVector.z) + Mathf.PI) / Mathf.PI *0.5f;
            ISOuv.y = (Mathf.Acos(unitVector.y) + Mathf.PI) / Mathf.PI - 1;
            UVs[i] = new Vector2(ISOuv.x, ISOuv.y);
        }
        mesh.uv = UVs;

@andSol , did you find any solution for that?

A cheat/simple solution which works for boulders , asteroids and similar objects is to make sure that the U (or V - whichever you have the problem with) coordinate starts at 0.0 , goes to 1.0 and then back to 0.0.

The opposite side of the rock will have the same texture but … no seam.
Still you will have polar problems and such.
Super cheaty version is to simply

… Mathf.Atan( x , Mathf.Abs(z) ) …