c# - How do I reference a class in MyScripts from within another namespace (Unity)? -


i using unity 5.3.5. have script wrote under unity assets/myscript folder.

scripta.cs

public class scripta : monobehaviour {     //code here     public static bool flag_i_want_to_reference; } 

then, because using unity standard asset vehicle/car thing, in separate namespace in different folder path (i.e. not in myscripts folder in different path under assets)

somecarscript.cs

namespace unitystandardassets.vehicles.car {     public class somecarscript : monobehaviour     {         //code here         bool foo = scripta.flag_i_want_to_reference;     } } 

now, have bool want reference within somecarscript.cs getting error the name 'scripta' not exist in current context

i trying figure out class/reference need have using statements on top of somecarscript.cs script make work. have tried looking global namespaces , tried global::scripta.flag_i_want_to_reference , global::flag_i_want_to_reference doesn't work. have tried using "assets/myscripts/scripta.cs;" doesn't work either.

any appreciated.

this looks compilation order issue.

if somecarscript in subdirectory of "standard assets" folder , scripta somewhere else, it's because of compilation order scripta can't referenced. scripta compiled in phase after somecarscript , therefore not exist somecarscript.

all code compiled in specific phase can access code compiled in same phase or earlier phase, not code compiled in later phase (because, code being compiled, doesn't exist yet).

general practice keep code referencing standard assets scripts in folder other "standard assets", compiled @ later stage , able access other code.

coming solution, have two options:

  1. move scripta same directory somecarscript (not recommended)
  2. move somecarscript directory not subdirectory of "standard assets", "pro standard assets" or "plugins" (recommended)

check out unity manual page concerning script compilation order more information.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -