Files
Rebirth/Assets/Network.cs
2024-12-15 03:08:48 -06:00

44 lines
954 B
C#

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class Network : MonoBehaviour
{
private List<Planet> _planets;
public Planet planetPrefab;
public void AddPlanet()
{
var planet = Instantiate(planetPrefab);
planet.GenerateLine();
planet.name = $"Planet {_planets.Count + 1}";
planet.transform.parent = transform;
_planets.Add(planet);
}
/// <summary>
/// Signal that a planet has been destroyed
/// </summary>
/// <param name="destroyed"></param>
public void Destroyed(Planet destroyed)
{
_planets.Remove(destroyed);
foreach (var planet in _planets)
{
if (planet != destroyed) continue;
planet.neighbors.Remove(destroyed);
}
}
void Start()
{
_planets = new List<Planet>(FindObjectsOfType<Planet>());
AddPlanet();
}
void Update()
{
}
}