5Y5T3M/Assets/Scripts/GameManager.cs

63 lines
1.6 KiB
C#
Raw Normal View History

2025-09-15 23:01:07 +02:00
using UnityEngine;
using System.Collections.Generic;
using System;
public class GameManager : MonoBehaviour
{
[HideInInspector]
public static GameManager instance;
[Header("Parameters")]
[Range(0, 100)]
public float maxConnectionLength;
public List<Node> nodes = new List<Node>();
[SerializeField]
public List<Connection> connections = new List<Connection>();
[Serializable]
public struct Connection
{
public Node nodeA, nodeB;
public bool allowed;
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
foreach (Node nodeA in nodes)
{
foreach (Node nodeB in nodes)
{
bool conExists = false;
if (nodeA == nodeB || Vector3.Distance(nodeA.transform.position, nodeB.transform.position) > maxConnectionLength)
break;
foreach (Connection con in connections)
{
if ((con.nodeA == nodeA && con.nodeB == nodeB) || (con.nodeA == nodeB && con.nodeB == nodeA))
{
conExists = true;
break;
}
}
if(!conExists)
connections.Add(new Connection { nodeA = nodeA, nodeB = nodeB});
}
}
}
// Update is called once per frame
void Update()
{
foreach (Connection con in connections)
{
Debug.DrawLine(con.nodeA.transform.position, con.nodeB.transform.position, con.allowed ? Color.green : Color.red);
}
}
}