i have 2 meshes that ive tried to turn into a 2 submeshes but it just sort of combines them when i do it, does anyone know why?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class plane : MonoBehaviour
{
public GameObject obmesh1;
public GameObject obmesh2;
public int[] triangles1;
public int[] triangles2;
public Vector3[] verticies1;
public Vector3[] verticies2;
public Vector3[] allverticies;
public Vector2[] uvs1;
public Vector2[] uvs2;
public Vector2[] alluvs;
// Start is called before the first frame update
void Start()
{
Mesh mesh1 = obmesh1.GetComponent<MeshFilter>().mesh;
Mesh mesh2 = obmesh2.GetComponent<MeshFilter>().mesh;
Mesh mesh = GetComponent<MeshFilter>().mesh;
//mesh.Clear();
mesh.subMeshCount = 2;
Debug.Log("Submeshes: " + mesh.subMeshCount);
int[] triangles1 = mesh1.GetTriangles(0);
int[] triangles2 = mesh2.GetTriangles(0);
verticies1 = mesh1.vertices;
verticies2 = mesh2.vertices;
allverticies = verticies1.Concat(verticies2).ToArray();
uvs1 = mesh1.uv;
uvs2 = mesh2.uv;
alluvs = uvs1.Concat(uvs2).ToArray();
mesh.uv = alluvs;
mesh.vertices = allverticies;
mesh.SetTriangles(triangles1, 0);
mesh.SetTriangles(triangles2, 1);
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
}