❔ Getting a variable from a GameObject without dragging and dropping it in
Forenote: For unity
Is there any way to get a variable from a GameObject without dragging and dropping it in?
6 Replies
Could you be a bit more specific?
A variable from a Logic Manager is needed for an object that gets spawned in and deleted constantly. I need it to use the variable in its script but I cant simply put the Logic Manager in the place specified in the image.
I'm still not quite sure. Could you explain what you're trying to do without the specifics?
But you can look into scritptable objects or statics
Im making a game where asteroids spawn and you have to dodge them. I want them to progressively speed up over time but because they keep being spawned in and deleted, I cant just put the code into its script because its time based and its the time from spawning it in. So I have the code in a Logic Manager. I have the variable I need for it to speed up but I need it to be used in the asteroids and I cant drag and drop it in because again, the timer restarts every time it spawns.
Suppose there's a scriptable object with a float value like speed. All of your objects can require this value as a serialized field as a dependency and can read from this value.
Your Logic Manager can update this value
On the event that the game restarts you can adjust the speed value accordingly 🌸
hope this helps
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.