Hello
I haven’t find anything on this so I thought I’ll give this a shot:
I have a script (Transformer) which takes a float and alters it (with perlin noise, sinus, etc.).
I put this script on a GameObject.
How can I link let’s say the Y rotation of the GO to this float in the script via Inspector?
Thing is I don’t always want to alter the Y rotation but maybe a light’s intensity or a scale or anything else. so I need to be able to link values (floats, Vectors) dynamically, like I’m able to do with textures, gameobjects etc. etc by drag & drop.
Thanks in advance!
You could create a component that runs in Edit Mode ([ExecuteInEditMode]) that you use to make the links, there is nothing built in to do that but it could be a very useful script if you want to link things together in this way. If you used reflection to get and set the values then it could be quite flexible - the only problem being that changing just one part of a Vector3 would probably need a specific code path.
- Create a class flagged with ExecuteInEditMode
- Create two Component references for source and target
- Create two string variables to describe the value to read and the value to set
- Use reflection to get the FieldInfo for the source and target properties on the objects
- Check for changes in the Update function of the new class and apply changes
Clearly this would be simple if you just linked a direct value - the code path for a Vector3 involves reading the vector, updating the component and writing it back again - this happens with anything that is a struct (value type).