🤔

CS0106#

The modifier 'modifier' is not valid for this item

Modifiers are keywords that describe additional information about a subject; such as its visibility, usage, immutability.
Modifiers can only be applied in certain contexts, and the compiler will issue this warning when one is improperly applied.

Resolution#

Remove the conflicting modifier, it is likely invalid and not required.
Examples of modifiers include public, private, static, abstract—see access modifiers.

warning

Certain cases may require declaring the member in the correct scope.
For example, message functions1 should be declared in the class scope.

Example:#

public void Start()
{
LocalFunction();

public void LocalFunction()
{
// ...
}
}

Removing the modifier#

Local functions are always implicitly private. Remove public and it will compile.

-public void LocalFunction()
+void LocalFunction()
warning

Message functions1 will not be called if they are local functions.
If you're using a message function, move the local function to the class scope.

Moving a local function to the class scope#

In some cases the function should not be local to a method.

public void Start()
{
    Function();
}

public void Function()
{
    // ...
}

This error may manifest itself in other forms of modifier misuse. Generally removing the modifier will fix the issue.

  1. A message function is a callback sent to a MonoBehaviour, Update, OnTriggerEnter, and so on. See Messages.