Referencing NON-monobehavior scripts - getting an error :/

ok so heres the issue, my questing is not in regards to the details but to the generality of it all.

2 scripts:
1.)the first one is a NON monobehavior script, instead its set as [System.Serializable].
2.)the second one IS a monobehavior script.

the 1st script is called Enemy, and its variables can be referenced in “void ObtainEnemyID (Enemy enemy)” just fine.

but, the debug wont allow the script to pass because of the missing information that it requires
at “ObtainEnemyID();”.

im pretty convinced that this has a simple solution, just not sure exactly what i need to place within the parentheses.

i dont want to bug you guys with a million lines of code, so i broke the question down to (what i believe) is the root of the problem.

thanks so much for your help and brain power.

-r1pnd1p :slight_smile:

if (CONDITIONS) {

  ObtainEnemyID();  //error: non overload for method 'ObtainEnemyID' takes '0' arguments.
 }
 
   void ObtainEnemyID (Enemy enemy)
 {
  enemy.enemyID = enemyai.id;
 }

As it currently stands your function ObtainEnemyID requires a parameter of type Enemy, which is why you’re getting the error. You can either create a new Enemy object and pass it into the function when you call it or you can make it so that the function’s parameter is optional by setting it equal to null like this:

public void ObtainEnemyID (Enemy enemy = null)
{
   // function contents
}

What this will do is let you call the function with no parameter, setting the default to null (or whatever you want it to be). Another option you have is to ‘overload’ the function with another function of the same name and different parameters:

public void ObtainEnemyID()
{
   // function contents
}

public void ObtainEnemyID(Enemy enemy)
{
   // function contents
}

With this method you can declare a specific function for a given parameter type which enables you to do something unique in that case, but you’ll have to write another implementation for it. Hopefully this answers your question, if I misread it let me know.