Limiting Spawn Number

So I’ve been at this for the pas t 6 hours… should be a fairly simple thing.
spawns around 160ish fighters when it should only spawn 3.

this script SHOULD work however unity is ignoring these rules completely:

if (CurrentFighters == FighterCapacity) {
		SpawnFighters = false;
	}

	if (CurrentBomber == BomberCapacity) {
		SpawnBombers = false;
	}

overtime I launch a fighter I’m setting the count to +1 however I get way more then the Max level of fighters…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CarrierBay : Photon.MonoBehaviour {

	public float FighterCapacity = 3;
	public float BomberCapacity = 2;

	public float CurrentFighters = 0;
	public float CurrentBomber = 0;


	public bool IsOurs;
	public bool SpawnFighters;
	public bool SpawnBombers;

	public CarrierAI CarrierScript;
	public GameObject CarrierGameObject;


	//----------------------------------------------------------------------------------------------------------------

	void Start () {
		CarrierScript = CarrierGameObject.GetComponent<CarrierAI> ();
		SpawnFighters = true;
	}


	//----------------------------------------------------------------------------------------------------------------


	
	// Update is called once per frame
	void Update () {


		if (CurrentFighters == FighterCapacity) {
			SpawnFighters = false;
		}


		if (CurrentBomber == BomberCapacity) {
			SpawnBombers = false;
		}

			//----------------------------------------------------------------------------------------------------------------
		if (PhotonNetwork.isMasterClient == true) {
			//----------------------------------------------------------------------------------------------------------------



			if (SpawnFighters == true && IsOurs == true) {
				CurrentFighters += 1;
				PhotonNetwork.Instantiate ("T1Fighter", this.transform.position, this.transform.rotation, 0);
			}


			if (SpawnBombers == true && IsOurs == true && CarrierScript.distance < 1200) {
				CurrentFighters += 1;
				PhotonNetwork.Instantiate ("T1bomber", this.transform.position, this.transform.rotation, 0);
			}











			if (SpawnFighters == true && IsOurs == false) {
				CurrentFighters += 1;
				PhotonNetwork.Instantiate ("T2Fighter", this.transform.position, this.transform.rotation, 0);
			}


			if (SpawnBombers == true && IsOurs == false && CarrierScript.distance < 1200) {
				CurrentBomber += 1;
				PhotonNetwork.Instantiate ("T2bomber", this.transform.position, this.transform.rotation, 0);
			}







	
		}
	}


	//----------------------------------------------------------------------------------------------------------------



}

I’m not too familiar with photon but the code looks like it should work. Only problem I have is that you are using floats for integers and i’m guessing there is somehow a problem with that… float equality checks are… lets say, not the greatest.

public int FighterCapacity = 3;
public int BomberCapacity = 2;
 
public int CurrentFighters = 0;
public int CurrentBomber = 0;

Also you should maybe make your checks something like

if (CurrentFighters >= FighterCapacity)

The problem is that your update function looks like the following psuedo or at least that’s what you gave me:

update()
{
  check if capacity == current
  spawn two fighters
  spawn two bombers
}

With that logic CurrentFighters will go from 0 to 2. the capacity == current check is false. Then next run, it goes from 2 to 4. Then it’s past the point. It won’t come true unless you are decrementing CurrentFighters