Hello everyone.
I’m trying to create a simple struct to hold data (not methods, just some properties), and I want it to be accessible from all my other scripts, like if it was just another class from the unity engine (Vector3 for example).
So I mostly know the differences between struct and class, and I want it to be a struct, not a class.
So how should I do it? As far as I know, unity doesn’t let me attach a script with just a struct declaration, scripts are classes which inherit from monobehaviour, and structs cannot be inherited from classes (correct me if i’m wrong) so how do I declare the struct? Should I declare it inside of a public class, and then attach that script onto a gameObject? Or is there a better way to do this?
Just tested it and it worked, but I don't fully understand why. So if I define a struct inside a script (not into the class which corresponds to that script), where am I actually defining it? Inside monoBehaviour? Is because of that that all the other scripts which inherit from monoBehaviour recognise my new variable type and are able to use it? Thank you ^^
– Setzer22That was helpful, I was also wondering a while ago how I could create a helper class to hold some useful methods which could be useful in all my scripts, now I know how to do it. Thank you very much
– Setzer22