Hi everyone. My question is simple, and I suppose the answer is simple, but I haven’t found out the solution yet. I’m using Unity 5.0.2 and doing some practices with the new first person controller. I would like to access other script’s variables from this script, but as this controller is into a namespace, It does not find the other script, that has no namespace… If I try to access the controller from another script I just have to put the complete namespace and it works.
How could I access the variable of another script from the controller?
Thanks.
If I understand correctly, what you want is to access a variable/function form another MonoBehaviour.
any member that is not static won’t be accessible unless you have access to an instance of the Monobehaviour. If the other script is in the same gameObject as the CharacterController, you cna access the instance by calling
YourClassName myInstance = GetComponent();
then myInstance.MyPublicProperty;
Try creating an instance of the other file i.e
public class TestClass : MonoBehaviour {
public ClassIWant EasyNameToFind;
public void SomeFunction(){
EasyNameToFind.TheFunctionYouWant();
or
EasyNameToFind.SomeVariable = TheModifiedValue;
}
}
That should be a simple enough way to do it, if I’m understanding you correctly. The “EasyNameToFind” class would then show up in the inspector of your class you’re accessing it from, aslong as the Class You want is Serialized