最近研究了一下GameObject的mesh和纹理,特地写了一个demo来实现根据线生成墙
代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class wasd : MonoBehaviour
{
public Material mater;
private GameObject gameObject;
private GameObject simpleMesh;
private float speed = 20f;
private float mousespeed = 200f;
Vector3 oldMousePosition;
Vector3 newMousePosition;
class GISPoint
{
public float x;
public float y;
public GISPoint(float x1,float y1)
{
x = x1;
y = y1;
}
}
void createWallByPoints(List<GISPoint> points,float wall_height, Mesh mesh)
{
float wall_height2 = 1.0f;
float wall_length2 = 1.0f;
int pntCount = points.Count;
int rectCount = pntCount - 1;
int vertCount = rectCount * 4;
Vector3[] verts= new Vector3[vertCount];
for (int i = 0; i < rectCount; i++)
{
verts[i*4] = new Vector3(points[i].x, 0, points[i].y);
verts[i*4+1]= new Vector3(points[i].x, wall_height, points[i].y);
verts[i*4+2] = new Vector3(points[i+1].x, wall_height, points[i+1].y);
verts[i*4+3] = new Vector3(points[i+1].x, 0, points[i+1].y);
}
mesh.vertices = verts;
int[] triangles = new int[rectCount * 2*3];
//n=ponitIndex; n(2n,2n+1)
//p (3P,3P+1,3p+2)