Created
January 8, 2018 12:25
-
-
Save josephbk117/dffa73d06fd4adc8e75db8fa1059acd0 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