- Home /
Outdated
Give an specific parameter of my GameObject to a Script using the Inspector
Hello everyone, I'm starting to do some editor scripting and then I wonder if you can do the next:
Given a GameObject field of some sort access in the Inspector to all the public fields it may have in his attached scripts, so I can access them inside the script where I inserted this GameObject.
An example of this would be have a general script called "ShooterListener" so inside the script I listen to some value of a given variable specified in the inspector, this way I can change the variable I need the script to listen to without modifying the script itself.
Hopefully it's not too confusing to understand.
You could use reflection to do this, perhaps also with the use of expression trees. Hopefully those are some good starting points to research
Answer by Foulcloud · Aug 24, 2015 at 09:53 PM
Create a script with one or more public variables. Attach the script to a game object. You can now edit the public variables in the editor. The script will know whatever values you have changed in the editor. You can assign unique values to each different game object. For example, if you have a prefab "car" with a script attached that has a public variable "speed" then you can assign each different car in the scene a different speed.