Hi. I’ve a question about using classes.
I never learned programming and the tutorials helped me a lot; but finding the best solution is still a quest at its own.
For an inventory system, where you drag an item into a canvcas inventory window, the item object will be disabled and an item canvas will be created representing the item in the inventory, I need a script that handles both the drag of the item object and the actions taken to creat the canvas (that script must be seperated from the inventory window).
To simplify the process, I thought about using a class to do all that stuff I can call from other scripts (like the inventory canvas event raycast system that recognizes the cursor moving into the inventory).
Now, is that the meaning of a class to ‘work’ in the background and be called from any script that needs it without beeing present in the scene at all? That would simplify a lot of things:
-
InventoryScript as class somewhere in the project folder, not in the scene, connecting actions from inventory canvas and cursor actions.
-
CursorActionScript, handling a ScreenpointToRay raycast to select item objects in the game world.
-
InventoryCanvasScript, present as component at the inventory canvas recognizing cursor event (OnPointerEnter) to call different actions by the InventoryScriptClass.
-
=> no need to get reference to a ‘master-inventory-handler-script’ somewhere in the scene that must be called from both scripts to work together.
Or is there even a better solution?