Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections.Generic;
- //[ExecuteInEditMode()]
- public class PlaneManipulation : MonoBehaviour {
- Ray ray;
- RaycastHit hit;
- Mesh mesh;
- private Vector3[] vertices;
- public float rayLength;
- //public LayerMask planeLayer;
- private float yOffset;
- void Start()
- {
- //mesh = GetComponent<MeshFilter>().mesh;
- //Debug.Log("count = " + mesh.vertexCount);
- // vertices = mesh.vertices;
- // ChangeMesh();
- }
- void ChangeMesh() {
- mesh = GetComponent<MeshFilter>().sharedMesh;
- //mesh.Clear();
- vertices = mesh.vertices;
- //using only the first row of the vertices from the plane
- for (int i = 0; i < 11; i++)
- {
- Vector3 vert = transform.TransformPoint(vertices[i]);
- //ray = new Ray(vert,Vector3.up);
- //Debug.Log("bitch");
- Physics.Linecast(vert, 100 * Vector3.up, out hit);
- Debug.DrawRay(vert, Vector3.up);
- vert.y = hit.point.y;
- //vertices[i].y = hit.point.y;
- vertices[i] = transform.InverseTransformPoint(vert);
- }
- mesh.vertices = vertices;
- mesh.RecalculateNormals();
- mesh.RecalculateBounds();
- }
- void Update() {
- ChangeMesh();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement