i have written this code to spawn a segments of enemies i don't get errors at all but it didn't work .. what should i do ?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LevelManegar : MonoBehaviour {

	public static LevelManegar Instance { set; get;}

	private const bool SHOW_COLLIDER = true;

	//Level Spawner

	private const float DESTANCE_BEFORE_SPAWN = 100f;
	private const int INITIAL_SEGMENT = 10;
	private const int MAX_SEGMENTS_ON_SCREEN = 15;
	private Transform cameraContainer;
	private int amountOfActiveSegments;
	private int continiousSegments;
	private int currentSpawnZ;
	private int currentLevel;
	private int y1, y2, y3;


	//Lest of Pieces
	public List<Piece> ramps = new List<Piece> ();
	public List<Piece> longblock = new List<Piece> ();
	//public List<Piece> jumps = new List<Piece> ();
	public List<Piece> slides = new List<Piece> ();
	[HideInInspector]
	public List<Piece> Pieces = new List<Piece> (); //All the pieces in the pool

	//List of Segments
	public List<Segment> availableSegments = new List<Segment> ();
	public List<Segment> availableTransitions = new List<Segment> ();
	[HideInInspector]
	public List<Segment> segments = new List<Segment> ();

	//Game Play 
	private bool isMoving = false;

	private void Awake() {

		Instance = this;
		cameraContainer = Camera.main.transform;
		currentSpawnZ = 0;
		currentLevel = 0;
	}

	private void Start() {
	
		for (int i = 0; i < INITIAL_SEGMENT; i++)
			GenerateSegment ();
	}

	private void GenerateSegment() {
	
		SpawnSegment ();

		if (Random.Range (0f, 1f) < (continiousSegments * 0.25f)) {
			//Spawn Transition Seg
			continiousSegments = 0;
			SpawnTransition ();
		} 
		else 
		{
			continiousSegments++;
		}

	}

	private void SpawnSegment ()
	{
		List<Segment> possibleSeg = availableSegments.FindAll (x => x.beginY1 == y1 || x.beginY2 == y2 || x.beginY3 == y3);
		int Id = Random.Range (0, possibleSeg.Count);

		Segment s = GetSegment (Id, false);

		y1 = s.endY1;
		y2 = s.endY2;
		y3 = s.endY3;

		s.transform.SetParent (transform);
		s.transform.localPosition = Vector3.forward * currentSpawnZ;

		currentSpawnZ += s.length;
		amountOfActiveSegments++;
		s.Spawn ();
	}

	private void SpawnTransition ()
	{
		List<Segment> possibleTransition = availableTransitions.FindAll (x => x.beginY1 == y1 || x.beginY2 == y2 || x.beginY3 == y3);
		int Id = Random.Range (0, possibleTransition.Count);

		Segment s = GetSegment (Id, true);

		y1 = s.endY1;
		y2 = s.endY2;
		y3 = s.endY3;

		s.transform.SetParent (transform);
		s.transform.localPosition = Vector3.forward * currentSpawnZ;

		currentSpawnZ += s.length;
		amountOfActiveSegments++;
		s.Spawn ();
	}


	public Segment GetSegment( int Id, bool transition)
	{
		Segment s = null;
		s = segments.Find (x => x.segId == Id && x.transition == transition && !x.gameObject.activeSelf);

		if (s = null) {
			GameObject go = Instantiate ((transition) ? availableTransitions [Id].gameObject : availableSegments [Id].gameObject) as GameObject;

			s.segId = Id;
			s.transition = transition;
			segments.Insert (0, s);
		} 
		else 
		{
			segments.Remove (s);
			segments.Insert (0, s);
		}

		return s;
	}
		
	public Piece GetPiece(PieceType pt, int visualIndex){
	
		Piece p = Pieces.Find (x => x.Type == pt && x.visualIndex == visualIndex && !x.gameObject.activeSelf); 

		if (p == null) 
		{
			GameObject go = null;
			if (pt == PieceType.ramp)
				go = ramps [visualIndex].gameObject;
			else if (pt == PieceType.longblock)
				go = longblock [visualIndex].gameObject;
			//else if (pt == PieceType.jump)
				//go = jumps [visualIndex].gameObject;
			else if (pt == PieceType.slide)
				go = slides [visualIndex].gameObject;

			go = Instantiate (go);
			p = go.GetComponent<Piece> ();

			Pieces.Add (p);
		}

		return p;
	}
}

My guess is that it’s this line:

if (s = null) {

Broken down into how that actually executes, that does these things, in order:

  1. Assign null to s
  2. Convert s (which is now null) to a boolean (which will be false)
  3. Test the boolean and choose a branch (which will be the else branch)

Your else branch does not re-initialize s, because (I assume), that’s the branch you intended to execute when s was not null.

The fix is pretty simple:

if (s == null) {

That, instead, does these things:

  1. Test if s is null
  2. If true, goes into the if block
  3. If not, goes into the else block

It’s an easy mistake to make and one for which the Unity platform designers share a little bit of blame. This is the wages of an implicit conversion to bool, but in test-driven development there is mitigation of such implicit conversions.

I’m sorry, but have you tried Debug.Log(); to see where it actually reaches on the script? And if your enemies are spawning just not showing? Did you remember to attach the script to an object?