I’m trying to make a script that contains a function (let’s say it increments input by 1) and it runs this function on variables in other scripts. The trouble is it’s used on all different types of scripts and all different types of variable names (always the same type though, floats in this case).
Is there any way to get a variable reference to this function script without using additional scripts or changing the referenced scripts?
I was thinking something with dragging the reference script to the function script via the inspector, then filling out a string in the inspector with the name of the variable to grab. But as far as I know won’t work because you can’t get a variable reference from a string.
In my case it’s something along the lines of one script holding a velocity value and another wants to change it. The scripts that want to change velocity (or some other value) are called at different times and then set velocity accordingly. One script for instance sets a characters velocity based on how long a button was held down, but then in another case is used to set how strong an attack is (still based on how long a button is held down), and in another case is used to determine what color the character glows while holding the button down (by giving a glowColor script the value).
Hypothetically I could make a script reference that already knew that it would be referencing playerMovement.velocity (or whatever) but I would need one for each script it talks to and run a check to find out which one I would be using. Currently my solution is containing a SetVelocity(float input) function inside of the player movement script, but I need to do this for quite a few scripts and values so it’s more of a hassle than it should be.