Assigning uvs to "procedural" mesh.

This mesh is not technically procedural as in it’s a script that creates a new mesh but it’s a low poly water script that produces waves using the given mesh’s vertices. I did not create this script and it can actually be downloaded for free [HERE][1]. The only annoying concern is that it doesn’t do anything at all to effect the uvs. This is my current version of the script.

PLEASE KEEP IN MIND, I AM NEW TO CODING, So try to dumb it down for me please lol also I know what uvs are and all that I just have no idea of the code I need to write to actually SET the uvs.

using System.Collections;
using System.Collections.Generic;

using UnityEngine;

namespace LowPolyWater
{
	public class LowPolyWater : MonoBehaviour
	{
		public float waveHeight = 0.5f;
		public float waveFrequency = 0.5f;
		public float waveLength = 0.75f;
		public bool clampY = true;
		public bool _Gizmos = false;
		// private float _NewGizmoY;
		public float _GizmoY = 5f;
		public Color32 _GizmoColor;

		//Position where the waves originate from
		public Vector3 waveOriginPosition = new Vector3 (0.0f, 0.0f, 0.0f);

		private Mesh mesh;
		private MeshCollider meshCollider;

		private Vector3[] vertices;
		private MeshFilter meshFilter;

		private void Awake ()
		{
			//Get the Mesh Filter of the gameobject
			meshFilter = GetComponent<MeshFilter> ();
			meshCollider = gameObject.GetComponent<MeshCollider> ();
		}

		void Start ()
		{
			// _NewGizmoY = transform.position.y + _GizmoY;
			CreateMeshLowPoly (meshFilter);
			// Debug.Log (transform.position.y);
			// Debug.Log (transform.position.y + _GizmoY);
		}

		/// <summary>
		/// Rearranges the mesh vertices to create a 'low poly' effect
		/// </summary>
		/// <param name="mf">Mesh filter of gameobject</param>
		/// <returns></returns>
		MeshFilter CreateMeshLowPoly (MeshFilter mf)
		{
			mesh = mf.sharedMesh;

			//Get the original vertices of the gameobject's mesh
			Vector3[] originalVertices = mesh.vertices;

			//Get the list of triangle indices of the gameobject's mesh
			int[] triangles = mesh.triangles;

			//Create a vector array for new vertices 
			Vector3[] vertices = new Vector3[triangles.Length];

			//Assign vertices to create triangles out of the mesh
			for (int i = 0; i < triangles.Length; i++)
			{
				vertices _= originalVertices[triangles*];*_

_ triangles = i;
* }*_

* //Update the gameobject’s mesh with new vertices*
* mesh.vertices = vertices;*
* mesh.SetTriangles (triangles, 0);*
* mesh.RecalculateBounds ();*
* mesh.RecalculateNormals ();*
* mesh.GetType ();*
* this.vertices = mesh.vertices;*
* mesh.uv = new Vector2[mesh.vertexCount];*

* meshCollider.sharedMesh = mesh;*

* return mf;*
* }*

* void Update ()*
* {*
* GenerateWaves ();*
* }*

* private void OnDrawGizmos ()*
* {*
* if (Gizmos)*
* {_
Gizmos.color = GizmoColor;
Gizmos.DrawWireMesh (mesh, -1, this.transform.position + new Vector3 (this.transform.position.x,this.transform.position.x + GizmoY, this.transform.position.z), gameObject.transform.rotation, this.transform.localScale);*
* }*

* }*

* ///

*
* /// Based on the specified wave height and frequency, generate*
* /// wave motion originating from waveOriginPosition*
* ///
*

* void GenerateWaves ()*
* {*

* //Count the vertices?*
* for (int i = 0; i < vertices.Length; i++)*
* {*
_ Vector3 v = vertices*;*_

* //Initially set the wave height to 0*
* v.y = 0.0f;*

* //Get the distance between wave origin position and the current vertex*
* float distance = Vector3.Distance (v, waveOriginPosition);*
* distance = (distance % waveLength) / waveLength;*

* //Oscilate the wave height via sine to create a wave effect*
_ v.y = waveHeight * Mathf.Sin (Time.time * Mathf.PI * 4.0f * waveFrequency +
(Mathf.PI * 2.0f * distance));_

* //CLAMP THE Y TO MINIMUM OF “waveOriginPosition.y” so the waves do not go below original y coordinates*
* if (clampY)*
_ v.y = Mathf.Clamp (v.y, waveOriginPosition.y, waveHeight * 4.0f + waveOriginPosition.y);_

* //Update the vertex*
_ vertices = v;
* }*_

* //Update the mesh properties*
* mesh.MarkDynamic ();*
* mesh.vertices = vertices;*

* mesh.RecalculateNormals ();*
* meshCollider.sharedMesh = mesh;*
* meshFilter.mesh = mesh;*
* // OnDrawGizmos ();*
* // mesh.uv.Initialize ();*

* }*

* }*
}
_*[1]: https://assetstore.unity.com/packages/tools/particles-effects/lowpoly-water-107563*_

Hi, @Cinabutts0

The question has been asked before: Generating UVs for a scripted mesh - Questions & Answers - Unity Discussions

Maybe it is helpful? It’s pretty much just plotting the vert positions in UV space.

@eses Yes that does help me but I can’t figure out where and how to get vertices*.x and y…*