I am working with Platformer Character 2D from the Standard Assets. In project pane I created a new script with public static variable bool. I want to access this public bool which is in a public class in the script of the 2D character which is in a namespace UnityStandardAssets._2D.
In the player script when I type the name of my public class it just do not show up…
Example: My public class:
public class Bumper : MonoBehaviour
public static bool bumper;
Script of the 2D character from the standard assets where I would like to access a variable bumper:
public class PlatformerCharacter2D : MonoBehaviour
// here I want to acces my public static bool bumper.
I guess you have the PlatformerCharacter2D script either inside “Standard Assets” or “Plugins” but your “Bumper” script outside. Things in those folders belong to a different compilation group. They are compiled before your actual scripts. Things in those folders must not have any dependencies to classes outside those folders. If PlatformerCharacter2D class needs access to your Bumper script, either move your Bumper script into Standard Assets as well or move your PlatformerCharacter2D class out of the Standard Assets folder.
method : Scriptname.variablename.
if the name of the script is X and the variable in that script that you want to access is y, you refer it in another script as X.y
If you are still confused here’s a link to Unity Learn tutorial about Statics : https://unity3d.com/learn/tutorials/modules/intermediate/scripting/statics
And a link to namespace
You need to include the name space. So any script that accesses the target script needs