Weird issue getting values from other scripts

I’ve got a problem where C# doesn’t seem to be able to find other scripts in the same namespace. I have two scripts in separate parallel folders that are both recognised by the visual studio tree. I try to use a bool or something like that with OtherScript.NameOfTheBool and it’s not detected for some reason even though the name of the script is showing green. I copy pasted the name, so I’m sure it’s spelt right, and they’re all public. I don’t know what’s going on, but I’m hoping someone can tell me.

 private void Update()
 {
            if (PlayerController.teleportMovement)
            {
                (script I know works)
            }
}

In PlayerController:

public bool teleportMovement = false;

did you get a reference to it? I think it’s only accessible if it’s static, otherwise, it needs a reference.

Yep this seems to be a fundamental misunderstanding how member variables, classes, and object instances work. teleportMovement belongs to a particular instance of PlayerController. Your script needs a reference to that particular instance in order to use it. Imagine if there were two PlayerControllers in the scene. How would the code know which one to use without a reference? I’d expect something like this to use that variable:

// This can be assigned in the inspector or in any way you want
public PlayerController thePlayer;

void Update() {
  // now we can access it here:
  if (thePlayer.teleportMovement) ...
}

Thank you! That worked!