I was wondering if it’s possible to set the properties of a game object when a script on that gameobject has one of its public properties filled.
There are Unity objects that do this already. Most UI objects update in editor when their Text or Image component is changed. If that’s possible for me to implement for my game objects that would be very helpful.
For example, say I had a bullet prefab that had a script component with a public damage property. It would be really helpful if when i set that variable, it affected the size/scale of the bullet.
Just to clarify, I want this to happen when the editor is NOT in play mode. It would be easy to write some code to change the size of the bullet when the game is running. I want it to change in the editor while the game is NOT running, like the UI elements I mentioned before.
Is this possible?
Thanks in advance
If I am getting your question correctly, I think let’s assume when damage is 50 and you change it manually to 70, you want the size to change from 10 to 12 by itself. Assuming all these are public variables. I don’t think unity will allow it unless you link them somehow using a code. And even in that case, it won’t change itself inside the editor, but only recalculate and update once you press play. By the way, why do you need this?
My real example is a little different. My player character has two weapon slots. I was hoping that I could set it up so when I drag a weapon into one of the slot fields on the player script, it would instantiate the weapon in the editor at a set transform (the players hand). This way I can see the weapon equipped to the character before I press play. I’m sure you can imagine why something like that would be pretty convenient.
Otherwise I have to manually drag the prefab into the hierarchy and set it’s transform, and delete it when i’m done with it. Or set it to instantiate and position itself on play, which is also a little annoying because I have to start the game just to see the result.
The bullet example was something i wanted as well, but not what inspired the question.