Mini-Games-Game/Assets/Scripts/MeshCombiner.cs

30 lines
859 B
C#
Raw Permalink Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//* General Comments or Finished Tasks
//TODO Tasks left to be done for game
//! Bugs or Issues
//? Questions or Suggestions
public class MeshCombiner : MonoBehaviour
{
[SerializeField] private List<MeshFilter> sourceMeshFilters;
[SerializeField] private MeshFilter targetMeshFilter;
[ContextMenu("Combine Meshes")]
private void CombineMeshes()
{
var combine = new CombineInstance[sourceMeshFilters.Count];
for (var i = 0; i < sourceMeshFilters.Count; i++)
{
combine[i].mesh = sourceMeshFilters[i].sharedMesh;
combine[i].transform = sourceMeshFilters[i].transform.localToWorldMatrix;
}
var mesh = new Mesh();
mesh.CombineMeshes(combine);
targetMeshFilter.mesh = mesh;
}
}