Change in Editor via Script Values of another Script
Hey guys, there are many "how to change values of a script" posts out there but none seems to suit my purpose.
Also here my Problem: My Game Designer wants one Script where he can change all Values from several other Scripts of an Object. Like: Manager - Damage - FireRate - HPMax - HPCurrent - Speed
ShootScript - Damage - FireRate HealthScript - HPMax - HPCurrent MovementScript - Speed
These Scripts are also may be in children or completely separate objects But this Values inside Manager must be distributed immediately in Editor view.
Please Help :D
Answer by Sgt_Spike · Jun 19, 2018 at 12:57 PM
Have you tried using static variables? For example, if you create an integer called 'number' in a script called 'ScriptA' and you want to change the value of 'number' in another script called 'ScriptB', you can declare the variable in ScriptA by using 'public static int number'. You can then access this value from any other script. You would need to put the script name and then the variable name in your other scripts though, in this case 'ScriptA.number = 4;'.
Static variables are definitely not what he's looking for. And they are not serialized, thus all designer work would be lost most likely
tried static seems not what I want cause I cannot say which specific game objects I want to change. The $$anonymous$$anager changes have to apply to specific objects not all.
Answer by DawidNorasDev · Jun 19, 2018 at 01:06 PM
The most simple solution (but not most clean) would be to make a separate script and make it have those values, designer in the end wants to edit. Look at method OnValidate()
Which is called every time something in inspector changes. So You can than populate values of the script to other simpler scripts in this OnValidate()
Your answer
Follow this Question
Related Questions
Animation/Movement Error 1 Answer
Visual Studio 2017 and Unity 2019 not communicating? 1 Answer
How to display random questions without repeating the previous? 2 Answers
C# - Cannnot access variable in another script unless I get the component everytime. 1 Answer
How to access non static C# variable from another C# script 1 Answer