Advertisement
kekekekkkkekke

planeChanging

Feb 22nd, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3.  
  4. //[ExecuteInEditMode()]
  5. public class PlaneManipulation : MonoBehaviour {
  6.  
  7. Ray ray;
  8. RaycastHit hit;
  9.  
  10. Mesh mesh;
  11. private Vector3[] vertices;
  12. public float rayLength;
  13.  
  14.  
  15. //public LayerMask planeLayer;
  16.  
  17. private float yOffset;
  18. void Start()
  19. {
  20. //mesh = GetComponent<MeshFilter>().mesh;
  21.  
  22. //Debug.Log("count = " + mesh.vertexCount);
  23.  
  24. // vertices = mesh.vertices;
  25.  
  26. // ChangeMesh();
  27.  
  28. }
  29.  
  30. void ChangeMesh() {
  31. mesh = GetComponent<MeshFilter>().sharedMesh;
  32. //mesh.Clear();
  33. vertices = mesh.vertices;
  34.  
  35. //using only the first row of the vertices from the plane
  36. for (int i = 0; i < 11; i++)
  37. {
  38.  
  39. Vector3 vert = transform.TransformPoint(vertices[i]);
  40. //ray = new Ray(vert,Vector3.up);
  41. //Debug.Log("bitch");
  42.  
  43. Physics.Linecast(vert, 100 * Vector3.up, out hit);
  44. Debug.DrawRay(vert, Vector3.up);
  45.  
  46. vert.y = hit.point.y;
  47.  
  48. //vertices[i].y = hit.point.y;
  49. vertices[i] = transform.InverseTransformPoint(vert);
  50.  
  51. }
  52.  
  53. mesh.vertices = vertices;
  54.  
  55. mesh.RecalculateNormals();
  56. mesh.RecalculateBounds();
  57. }
  58.  
  59.  
  60. void Update() {
  61.  
  62. ChangeMesh();
  63.  
  64. }
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement