Mini-Games-Game/Assets/Scripts/MeshCombiner.cs
Santi cac9e28067 Documentation: Added Whack-A-Mole PDF
Unity: Created Whak-A-Mole Prototype Scene, Script and Added Score Functinality
2024-05-02 12:57:13 +01:00

25 lines
733 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
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;
}
}