public void SpawnRail(float density, float size, float spawnAngleDiff, int segIndex, float killTime = 15f) { var isCorrupted = UnityEngine.Random.value <= corruptedRailOverrideChance; if (isCorrupted || Perlin.Noise01(Time.time * 5 + seed) <= density) { RailSegment r = CreateRailSegment(size, spawnAngleDiff, segIndex, killTime: killTime); if (isCorrupted) { r.SetCorrupted(true); corruptedRailOverrideChance *= 0.5f; } else { r.SetCorrupted(false); corruptedRailOverrideChance = 0; } } else { previousRailSegment = null; Vector2 rd = (transform.position - lastRailSpawnPosition).normalized; Vector2 normal = rd.Rotate(90); Debug.DrawRay(transform.position, normal, Color.blue, 3f); nodes.Add(new RailNode(segIndex, 0, transform.position, rd, normal, isCorrupted, false)); lastRailSpawnPosition = transform.position; } }