Это добавляет меш-коллайдер ко всем игровым объектам, а также префабам, даже если у детей в префабе уже есть коллайдеры. Проблема в том, что когда я заканчиваю игру, она перестает играть, а коллайдеры не добавляются. Как я могу сохранить коллайдеры?
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
public class GetComponents : MonoBehaviour
{
public Transform parent;
public List<GameObject> allObjects = new List<GameObject>();
private void Start()
{
string path = "e:/colliders.txt";
StreamWriter writer = new StreamWriter(path, true);
allObjects = FindObjectsOfType<GameObject>().ToList();
Transform[] allChildren = parent.GetComponentsInChildren<Transform>();
foreach (Transform child in allChildren)
{
if (child.name != "_Level" && child.name != "_Rocks" && child.name != "_Others" && child.name != "Base")
{
var colliders = child.GetComponents<Collider>();
int length = colliders.Length;
if (length == 0)
{
writer.WriteLine(string.Format("{0} - No Colliders", child.name));
child.gameObject.AddComponent<MeshCollider>();
}
else
{
//composes a list of the colliders types, this will print what you want e.g. "Wall1 - BoxCollider, MeshCollider"
string colliderTypes = string.Empty;
for (int i = 0; i < length; i++)
{
colliderTypes = string.Format("{0}{1}", colliderTypes, colliders[i].GetType().Name);
if (i != (length - 1))
{
colliderTypes = string.Format("{0}, ", colliderTypes);
}
}
//writer.WriteLine(string.Format("{0} - {1}", child.name, colliderTypes));
}
}
}
writer.Close();
}
}