...is it bad design to use puplic static variables for this?
Hi guys,
in my current project, I have one GameObject (only one and there will ne no second of this Kind) with a script on it, which a few components I have to manipulate from various other scripts. As for my understanding (I'm not very advanced) this would be a good use for "public static" access-descriptor. But I always read that "public static" is core of evil. Does it really matter when I have a few public static variables? The memory that's bound permanetly shouldn't matter for a few Arrays with ConfigurabeJoints and auch components, right? If you habe a better idea, I would be happy if you would share, but getting the script to every script that needs the array-data is quite annoying and bad for maintenance I think...
Looking forward to some I pur.
BR mat
There is nothing wrong in using static. I think you should use Singleton pattern in your scripts.
simplest example can be :
public class $$anonymous$$yScript: $$anonymous$$onoBehaviour
{
public static $$anonymous$$yScript instance;
public void Awake()
{
if (instance == null)
{
instance = this;
}
}
}
No need to have some static gameObject to getComponent, you can use directly $$anonymous$$yScript.instance.
What happens is you thought you'd only even have one of something. But later, the project grows, or something you didn't realize makes you need several, forcing you to rewrite w/o statics.
After you do that a few times, you stop saying "but this time I $$anonymous$$NOW I'll never need more than one," and use regular vars to begin with (which really isn't that much trouble.)