Answer the question
In order to leave comments, you need to log in
How not to find through the tag objects whose name is "Preview Scene"?
Good day Toaster! I ran into an interesting problem in my opinion, I don’t know if it’s a Bug or a Feature ... I have MeshCombiner, which in turn combines the rendering meshes into one and adds this result to the Calider and to the Physics script. I find it like this:
1) Create an array of Cases GameObject[] hulls;
-> Fill the array by searching for a specific tag
GameObject.FindGameObjectsWithTag("/*Название Тэга*/");
MeshFilter[] filters;
-> I fill it with a long array of Cases -> Then, through the for loop, I look for MeshFilters... filters = new MeshFilter[hulls.Length];
for (int i = 0; i < hulls.Length; ++i)
filters[i] = hulls[i].GetComponent<MeshFilter>();
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeshCombiner : MonoBehaviour
{
public GameObject[] hulls;
public MeshFilter[] filters;
public void CombineMeshes()
{
Quaternion oldRot = transform.rotation;
Vector3 oldPos = transform.position;
transform.rotation = Quaternion.identity;
transform.position = Vector3.zero;
hulls = GameObject.FindGameObjectsWithTag("Hull");
filters = new MeshFilter[hulls.Length];
for (int i = 0; i < hulls.Length; ++i)
filters[i] = hulls[i].GetComponent<MeshFilter>();
Debug.Log(name + "Комбинируем...");
Mesh finalMesh = new Mesh();
CombineInstance[] combiners = new CombineInstance[filters.Length];
for(int i = 0; i < filters.Length; i++)
{
if (filters[i].transform == transform)
continue;
combiners[i].subMeshIndex = 0;
combiners[i].mesh = filters[i].sharedMesh;
combiners[i].transform = filters[i].transform.localToWorldMatrix;
}
finalMesh.CombineMeshes(combiners);
finalMesh.name = "PlayerShipMesh";
GetComponent<MeshFilter>().sharedMesh = finalMesh;
GetComponent<FloatingGameEntityFlat>().buoyancyMesh = finalMesh;
GetComponent<MeshCollider>().sharedMesh = finalMesh;
transform.rotation = oldRot;
transform.position = oldPos;
}
}
Answer the question
In order to leave comments, you need to log in
Most likely, you find service objects of the editor. If they are hidden in the hierarchy, you can check Object.hideFlags and weed out those with the HideInHierarchy flag set .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question