-
-
Save belzecue/4787f1a435b6810100218ce8ec0236ee to your computer and use it in GitHub Desktop.
depth surface generated with the help of surface generator script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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