Hey all,
I am new to Unity and try to make a GUI.
For that, I want to disable the Controlfunction while the menu is showing.
The function I want to call is located in DualTouchControls → MoveTouchpad. There is a script attached called TouchPad. And in this script are the functions located. I can’t get it to find the TouchPad script.
What I have tried is:
TouchPad = GameObject.Find("DualTouchControls").GetComponentInChildren<TouchPad>();
but it marks TouchPad red, because it can’t find the script.
The script I want to call the functions from is attached to a Directional Light.
How do I access the functions in it?
Thanks a lot!
Which “TouchPad” is it marking red? Based on this, you’re giving a variable the same name as a class (a type). You need to change the name of the variable you’re assigning this component to, or if this is where you’re defining the variable, then you need to add a variable name, like so:
TouchPad touchPadScript = GameObject.Find("DualTouchControls").GetComponentInChildren<TouchPad>();
I have declared that variable at the beginning already.
The problem is that it can’t find the class at all.
Attached is an image of the code
Can you make a screenshot of your DualTouchControls GameObject and also of the GameObject you have TouchPad script attached to ?
For future reference, you need to post the exact error you get and copy as much of your scripts as you think might be relevant to the problem, not just a single line. Because I have so little information, I’m going to assume you know absolutely nothing and just explain the whole process here:
GameObject.Find(“name”) will locate a GameObject in your scene that has the name (not tag) of whatever is in the quotes. This has to be exact, right capitalization and right spelling, and it must be in the scene. It will return the GameObject, which you’re then using GetComponentInChildren() on. That will search for and find the component (script) attached to the object or its children, returning the first one it comes to and then stopping.
The Component name that you look for is the same as the Class name. If it says the “TouchPad” class doesn’t exist but you know that you’ve made a script with that name, then it’s because it’s in a different namespace, or it’s a nested class, or your capitalization/spelling of it are wrong. If you mean that it’s not finding the class because it’s just not returning anything, then it could also be that this component simply isn’t attached to the object you’re looking for or its children.
You are awesome! Thanks a lot for that detailed answer 
It was actually that the script is in an other namespace and I totally ignored that.
It’s now working.
And thanks for your effort explaining it to me, it’s a lot clearer right now.