Search Unity

Question The type or namespace "controllerScript" could not be found. Are you missing a using directive or...

Discussion in 'Editor & General Support' started by andrewcorvec, Jun 24, 2020.

  1. andrewcorvec

    andrewcorvec

    Joined:
    Jun 24, 2020
    Posts:
    6
    Hi, I'm trying to use the controllerScript class to reference a script on another object. When I use it as such, however, I get the error in the title. Here's the bit of code that screws up:

    Code (CSharp):
    1. controllerScript player_variables;
    Any help is appreciated.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    Did you define a class called "controllerScript"?
     
  3. andrewcorvec

    andrewcorvec

    Joined:
    Jun 24, 2020
    Posts:
    6
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    What's the name of the script class you are trying to get an instance of? That's the name that should be on the left side of your variable declaration. it's the type of thing. If you say:

    Code (CSharp):
    1. Apple a = gameObject.GetComponent<Apple>();
    Then "Apple" is the type of a. In other words a is an Apple. If you never made a class called Apple, the compiler is going to be confused. Anything you reference needs to be defined somewhere.

    Here's a good tutorial that explains a few different ways to accomplish what you're asking:
     
    andrewcorvec likes this.