public void SpawnUnit() { GameObject clickedOn = pInput.GetLastClicked(); if (clickedOn) { Structure s = clickedOn.GetComponent <Structure>(); if (s == null) { Debug.Log("hey spawn unit() there is no s : " + clickedOn.gameObject.name); return; } switch (s.myStructType) { case Structure.STRUCT_TYPE.HOMEBASE: HomeBase hb = clickedOn.GetComponent <HomeBase>(); //myProduceUnit = hb.ProduceWorker; if (hb.GetIsBuilding() == false) { hb.SetIsBuilding(true, hb.GetWorkerBuildTime()); } break; case Structure.STRUCT_TYPE.RAX: break; case Structure.STRUCT_TYPE.FACTORY: break; case Structure.STRUCT_TYPE.STARPORT: break; default: break; } // myProduceUnit(); } }