Apply texture to a mesh on all 3 sides

I am working on a marching cubes terrain, and I need to apply a texture to it. The problem is, I don’t know how to apply the texture so the mesh looks “normal” from any angle. Right now, Ive been doing this:

uvs = new Vector2[mesh.vertices.length];
for (var i=0; i < uvs.Length; i+=1) {
uvs <em>= Vector2(mesh.vertices_.x,mesh.vertices*.z);*_</em>

mesh.uv = uvs;
This code works, but the mesh doesn’t draw right when a part of the mesh is completely straight up. That is because my code only applys the texture onto the x and z plane. I’ve been looking online for solutions, and couldn’t find any source code. But I have learned that there is a way to apply texture on all 3 of the xyz planes, and simply blend the result together. Unfortunately, I have no idea how to do this.
If anyone out there knows how to apply a texture onto a mesh, please let me know. ( I know it will involve UVs and normals)
After doing further research, ive learned that what im trying to do is called triplanar texturing.

Anyone able to help?

You do indeed want to use triplanar texturing. Have a look at these resources:

Note that you are on the right track, but you don’t want to ‘combine the UVs’. Instead you sample the texture three times (once with each set of UVs) and then combine the results. You will need some good shader programming skills to do this - I don’t believe you can just use C#/JavaScript.