SoFunction
Updated on 2025-03-06

Solutions for public variables in C# that cannot be recognized by the unity panel

The fundamental reason is that public is not the only condition for variables that can be identified on the unity panel, and another condition is that they can be serialized.

For example, you declared the following class

using ;
using ;
using UnityEngine;
public class Wave
{
    public GameObject prefab;
    public int count;
    public float rate;
}

When declaring in another class, the following is:

public Wave[] waves;

This will naturally not be seen in the unity panel, because the classes you declare at will do not inherit from the serialized class.

Just declare inheritance, as shown below

using ;
using ;
using UnityEngine;
[]
public class Wave
{
    public GameObject prefab;
    public int count;
    public float rate;
}

Supplement: C# class modifiers public and internal

When a class is created in the namespace, the default modifier is internal.

effect:

Calls to classes can be implemented in the current namespace.

When the class modifier is public, it indicates that the class can be called not only in the current namespace, but also in other namespaces. like:

using system;
using ...;
namespace s1
{
 internal class A
 {
  ....
 }
        class B
        {
           A a=new A();//ok
        }
}

However, the following code will prompt an error:

using system;
using ...; 
namespace s1
{
 internal class A
 {
  ....
 }
        
}
  
using system;
using ...;
using s1;
namespace s2
{
    class B
    {
       A a=new A();//error,as A is an internal which can only be called in its packet
     }
}

The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.