I want to create a plane with n x 1 quads (ex: 10 x 1 quads).
I’m able to do so but half of the triangles are showing on one side and the other half on the other side.
First side:
[16439-capture.png*_|16439]
Other side:
[16440-capture2.png*_|16440]
How can i make it so all triangles are showing on the same side?
Here is the code i drop on the plane showed above:
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
public int rectanglesCount = 200;
private Vector3[] _vertices;
private int[] _triangles;
private Mesh _mesh;
private Vector3 _size;
void Start ()
{
_vertices = new Vector3[(rectanglesCount * 2) + 2];
_triangles = new int[(rectanglesCount * 6)];
_mesh = ((MeshFilter) GetComponent(typeof(MeshFilter))).mesh;
_size = collider.bounds.size;
InitiateRectangles();
}
private void InitiateRectangles()
{
_mesh.Clear();
// vertices
/*
order
0 --- 2
| |
| |
| |
1 --- 3
*/
float xSpace = _size.x / rectanglesCount;
float x = 0;
bool top = true;
x -= _size.y / 2;
for(int i = 0; i < _vertices.Length; i++)
{
_vertices*.x = x;*
_vertices*.z = 0.01f;*
* if (top)*
vertices*.z = size.y / 2;*
* else*
* {*
_vertices*.z = - _size.y / 2;*
* x += xSpace;*
* }*
* top = !top;*
* }*
* top = false;*
* // triangles*
_ /
triangles[0] = 0;_
_triangles[1] = 1;
_triangles[2] = 2;*
* _triangles[3] = 1;
_triangles[4] = 2;
_triangles[5] = 3;*
* _triangles[6] = 2;
triangles[7] = 3;
triangles[8] = 4;*
*/
* int index = 0;*
* for(int i = 0; i < (triangles.Length / 3); i ++)*
* {*
index = i * 3;_
* _triangles[index] = i;
triangles[index + 1] = i + 1;
triangles[index + 2] = i + 2;*
* }*
* _mesh.vertices = _vertices;
_mesh.triangles = _triangles;*
* mesh.RecalculateNormals();
mesh.RecalculateBounds();*
* }*
}
*
*