HELP! Passing a class to another void.

Hello guys.

Basically, there are many different scripts, for example : ScriptA, ScriptB, ScriptC…and there’s one script which gathers all the information, for example - ScriptALL.

If ScriptA activates - I want it to send all information about the gameobject (which is done already), except the class itself.

For example:
1.ScriptA:
void Start(){
ScriptALL.GatherInformation(Variable01,Variable02, Variable03, this)
}
2.ScriptALL:
static public void GatherInformation(int var01, string var02, float var03, ???){

???.Variable01++;
???.Variable02–;
???.Otherstuff…;

}
3. ScriptB:
void Start(){
ScriptALL.GatherInformation(Variable01,Variable02, Variable03, this)
}
4. ScriptALL:
static public void GatherInformation(int var01, string var02, float var03, ???){

???.Variable01++;
???.Variable02–;
???.Otherstuff…;

}
And so on… Is it possible to have a variable in a GatherInformation, WHICH IS A CLASS? It would be easy
if the class would not vary, but now I have many different classes to transfer. Any suggestions? Really need to solve it!Thanks!

You can create an interface for all the common properties of ScriptA, ScriptB, etc. It would look something like this:

public interface IScript
{
  int Variable01 { get; set; }
  int Variable02 { get; set; }
  string Otherstuff { get; set; }
}

Note that you can’t define variables in an interface, so you must convert them to properties.

Then you have all those scripts implement IScript and your GatherInformation method can now take an IScript.

But when GatherInformation takes the IScript, can it change the variables inside GatherInformation void, so the variables get changed on ScriptA or ScriptB?

Yes it can. You would change your GatherInformation like this:

static public void GatherInformation(int var01, string var02, float var03, IScript script){ ... }

Inside GatherInformation you can modify script.Variable01, script.Variable02, etc. It will modify the corresponding properties on the script that was passed in.