Skip to content

Instantly share code, notes, and snippets.

@josephbk117
Created January 8, 2018 12:25
Show Gist options
  • Save josephbk117/dffa73d06fd4adc8e75db8fa1059acd0 to your computer and use it in GitHub Desktop.
Save josephbk117/dffa73d06fd4adc8e75db8fa1059acd0 to your computer and use it in GitHub Desktop.
depth surface generated with the help of surface generator script
using UnityEngine;
public class SurfaceImitator : MonoBehaviour
{
public SurfaceGenerator reference;
public bool generateCollider = true;
private Mesh mesh;
private Vector3[] vertices;
void Start()
{
mesh = GetComponent<MeshFilter>().mesh;
vertices = mesh.vertices;
}
void LateUpdate()
{
vertices = mesh.vertices;
int counter = 0;
for (int i = 0; i < 11; i++)
{
for (int j = 0; j < 11; j++)
{
vertices[counter].y = reference.vertices[i].z;
counter++;
}
}
mesh.vertices = vertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
if (generateCollider)
{
Destroy(GetComponent<MeshCollider>());
MeshCollider colliderComponent = gameObject.AddComponent<MeshCollider>();
colliderComponent.sharedMesh = null;
colliderComponent.sharedMesh = mesh;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment