How to change variables that were the origins for parameters of a function with parameters.

I have a reload function that looks like this:

void Reload (int mag, int magsize, int ammo )
{
   int missing_ammo = magsize - mag;
   ammo -= missing_ammo;
   mag = magsize;
}

And when it gets called by different weapons…

Reload(mag_plasmagun, magsize_plasmagun, ammo_plasmagun);

…the actual plasmagun values don’t change after completing the reload.

I’ve found some info on the subject that states, that variables from which all the function parameters originate are not changed when those parameters are changed. Basically the parameters are only clones of the originals.

So do I need to make a separate reload for every weapon? Or is there a way to change the originals from a function with parameters?

This doesn’t have anything to do with functions specifically.

It’s just that value types get passed by value and reference types by reference.
See @Bunny83’s correction in the comments

// value types
int a = 0;
int b = 99;
a = b;
b = 100;
//a == 99, b == 100. a and b are still separate. Just the value of b got assigned to a

// reference types
GameObject a = new GameObject("0");
GameObject a = new GameObject("99");
a = b;
b.name = "100";
//a.name == 100, b.name ==100. a and b reference the same object

You have to make a reference type (a class) to store and pass around the values you want to change when reloading a gun.

Just arrange your classes like they are in real life:
A “Magazine” class that has “maxAmmoCount” and “ammoLeft” that decreases when you fire. A gun class that has a magazine variable. Your gun’s reload method takes in the new clip as a parameter and does whatever you want with the old clip and the ammo left in it. Maybe a “MagazineBelt” class with a collection of Magazines List<Magazine> where the clips get taken from.

So this doesn’t work

class Gun{
   public int ammo;
}

class ReloaderClass{
   public static void Reload(int ammo){
      ammo +=30;
   }
}
...
Gun gun = new Gun();
ReloaderClass.Reload(gun.ammo);

But this works

public static void Reload(Gun gun){
      gun.ammo +=30;
}
Reload(gun);