Search Unity

Importing a script from a path

Discussion in 'Scripting' started by boris1709, Oct 17, 2019.

  1. boris1709

    boris1709

    Joined:
    Dec 17, 2018
    Posts:
    3
    I have two scripts, Utils.cs, from two different assets.
    There is a script in the GeNa folder that is accessing the Utils.cs file in the uSurvival when it should not be.
    I was told this is because there is no namespace used in the uSurvival version.

    It would be basically impossible to do this because of updating changing both assets code. Is there any way I can just have a 'using' statement at the top or some other way to make sure I am accessing the script in the same folder as the code being run?

    Thanks
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    No, that's not possible. You will have to modify the files of at least one of those assets. I recommend leaving comments on the assets' pages requesting that they use namespaces.
     
  3. boris1709

    boris1709

    Joined:
    Dec 17, 2018
    Posts:
    3
    Alright thanks, I figured that.
     
  4. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    To elaborate: folders and filenames make absolutely no difference whatsoever when compiling your C# code. They're just for your organization. What matters is the source code inside the files.

    If you want to have 2 classes with the same name, you need to put them in different namespaces.

    (Having two files with the same name is actually totally fine, though, as long as the classes inside them have different names or different namespaces.)

    If your current code compiles and runs without errors, but you find yourself referencing a different class or function than you intended, I bet you've got an error other than just a naming conflict.
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Except for the Special Folders (TM). Folders named "Editor", "Plugins", etc are treated differently by the compiler.