For example, Vector3 is a class that’s accessible from any script. How can I make my own class like Vector3?
For example, say I want to make an item class. It has an integer called “id” that stores its Id number, a string called “imagepath” which stores the filepath of the item’s sprite, and a void methhod named “OnUse()” that is called when the player would try to use it. Where would I go to define this class?
Make a class that is not derived from MonoBehavior.
public class itemHelper {
public static int id;
public static string imagepath;
//constructor to assign variables
public itemHelper(int ID, string Path) {
id = ID;
imagepath = Path;
}
void OnUse() {
//on use logic
}
}
then in other scripts you can use itemHelper like so
itemHelper sword = new itemHelper(1, Application.dataPath + "/sword");
itemHelper spear = new itemHelper(2, Application.dataPath + "/spear");
All classes are visible to all other scripts. There are some methods of Vector3 that are static, which make them callable without an instance of Vector3.
Read more about it here. Static Classes - Questions & Answers - Unity Discussions