I was following along, but since I personalized the ship with the modules (a Macross Skull-1 inspired, pretty cool)
I cannot just find the mesh in the children of the prefab to hide them like the lesson. I did try to use a foreach loop and an array to find and hide the meshes in the children, but only hides the first mesh of the array.
I also tried a whole lot of different ways, but I believe this is the one that got me the closest to a solution, so here’s my code if anyone could help:
public class CollisionHandler : MonoBehaviour
{
[SerializeField] float levelReloadDelay = 1.0f;
[SerializeField] ParticleSystem explosion;
[SerializeField] GameObject[] meshChildren;
void OnTriggerEnter(Collider other)
{
StartCrashingSequence();
}
void StartCrashingSequence()
{
if (!explosion.isPlaying)
{
explosion.Play();
}
HideMeshInChildren();
GetComponent<PlayerControls>().enabled = false;
Invoke ("ReloadLevel", levelReloadDelay);
}
void ReloadLevel()
{
int currentScene = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentScene);
}
void HideMeshInChildren()
{
foreach (GameObject part in meshChildren)
{
MeshRenderer mesh = GetComponentInChildren<MeshRenderer>();
mesh.enabled = false;
}
}
}