private void SpawnWeapon() { int weaponIndex = Random.Range(0, spawnedPrefabs.Length); GameObject weaponPrefab = spawnedPrefabs[weaponIndex]; Vector3 pos = GetSpawnPosition(); GameObject spawnerObject = Instantiate(spawnerPrefab, pos, Quaternion.identity); ObjectSpawn spawner = spawnerObject.GetComponent <ObjectSpawn>(); spawner.SetPrefabToSpawn(weaponPrefab, this); }