Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to access code within a installed package from a script in the Assets folder?

Discussion in 'Scripting' started by carlosfgzz, Mar 30, 2021.

  1. carlosfgzz

    carlosfgzz

    Joined:
    Jan 23, 2021
    Posts:
    7
    Hi everyone!

    I have an empty GameObject on my scene that has a script located in "Assets>Scripts" folder, what I want to do is access a function from a script in a Prefab located also in the scene, this script is located outside the Assets folder, to be more specific, is located in my project under the Packages section because is a package I installed through the Package Manager but in Visual Studio it doesnt recognize it in the Assembly-CSharp project, instead it places it as "Miscellaneous Files". Also the external script is assigned to a namespace called WebXR.

    What do you suggest could be the best option to achieve this communication between foreign scripts?

    Thanks.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
  3. carlosfgzz

    carlosfgzz

    Joined:
    Jan 23, 2021
    Posts:
    7
    Thanks Joe for the quick answer. I followed the instructions on the post you shared and I got Visual Studio to recognize the scripts under the WebXR Assembly as shown in the image attached, but then I have not been able to reference the WebXRManager script from the MenuManager script, I get the following error: "The type or namespace name 'WebXRManager' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp"

    What could be the best way to get a reference to WebXRManager from MenuManager?

    Thanks.
     

    Attached Files:

  4. carlosfgzz

    carlosfgzz

    Joined:
    Jan 23, 2021
    Posts:
    7
    Finally I managed to get it to work. I'm new to Unity and I didn't know anything about assemblies so I did a quick research and I figured it out. What I did was to create an Assembly definition in my main scripts folder and assign a reference to the WebXR assembly and finally it recognized the references.

    Thanks for guiding me in the right direction.
     
    Sykey, BayernMaik and Stijn_RMDY like this.