I am trying to make a nice ocean for a little project yet I cannot for the life of me figure out how to update the mesh. I have tried some suggestions on other threads but nothing worked so I figured I would ask directly. The script is in C# and goes like so.
using UnityEngine;
using System.Collections;
public class Wavegen : MonoBehaviour
{
float scale = 1f;
float speed = 1.0f;
float noiseStrength = 1f;
float noiseWalk = 1f;
private Vector3[] baseHeight;
void Update () {
Mesh mesh = GetComponent<MeshFilter>().mesh;
MeshCollider collider = GetComponent<MeshCollider>();
if (baseHeight == null)
baseHeight = mesh.vertices;
Vector3[] vertices = new Vector3[baseHeight.Length];
for (int i=0;i<vertices.Length;i++)
{
Vector3 vertex = baseHeight*;*
<em>vertex.y += Mathf.Sin(Time.time * speed+ baseHeight<em>.x + baseHeight<em>.y + baseHeight_.z) * scale;_</em></em></em>
<em><em><em><em>vertex.y += Mathf.PerlinNoise(baseHeight<em>.x + noiseWalk, baseHeight_.y + Mathf.Sin(Time.time * 0.1f) ) * noiseStrength;_</em></em></em></em></em>
<em><em><em><em><em>_vertices *= vertex;*_</em></em></em></em></em>
<em><em><em><em><em>_*}*_</em></em></em></em></em>
<em><em><em><em><em>_*mesh.vertices = vertices;*_</em></em></em></em></em>
<em><em><em><em><em>_*mesh.RecalculateNormals(); *_</em></em></em></em></em>
<em><em><em><em><em>_*collider.sharedMesh = null;*_</em></em></em></em></em>
<em><em><em><em><em>_*collider.sharedMesh = mesh;*_</em></em></em></em></em>
<em><em><em><em><em>_*}*_</em></em></em></em></em>
<em><em><em><em><em>_*}*_</em></em></em></em></em>
<em><em><em><em><em>_*```*_</em></em></em></em></em>
<em><em><em><em><em>_*Is there a way to add the mesh to this and also do I have to delete the mesh that appears when you create the object? (PS sorry bout the formatting errors I don't know what is making it do that) Edit: updated the script with a few lines but they seem to do nothing.*_</em></em></em></em></em>