Hi, I am trying to find another way to reference a script so that another script can use its info(variables, etc)
I have been using a way that has been successful, but produces annoying error.
Here is the code
var other = gameObject.GetComponent(PlayerMovement);
like I said it works, but produces an error such as this
“UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.
If you are using C# don’t use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function.
UnityEngine.Component.get_gameObject () (at C:/BuildAgent/work/cac08d8a5e25d4cb/Runtime/ExportGenerated/Editor/UnityEngineComponent.cs:183)
NoMovement…ctor () (at Assets/Scripts/NoMovement.js:5)”
Normally this wouldnt bother me much, but these errors are starting to build up
Any help would be greatly appreciated! Let me know if you need additional info!