Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a class for unity that can be used for every script?

I’m building a game in Unity which has some buyable skills in it. The bought skills are going to be stored in an external save file. Then being converted to a class called PlayerData. I want to make this class can be accessable from other scripts without typing the same class again in that script.

Is there a way to make like a global class? That can be accessed from other scripts?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I’m not sure exactly what you mean by

without typing the same class again in that script.

But if you mean you can’t access the class in other scripts, maybe you defined the class in another class?

Or do you mean you can’t access methods/variables directly without stating "of which instance of the class", in that case, you can use static class:
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading