- Home /
Using C# how can I setup a "database" script?
I wan't to setup a "database" that can be "looked up" from other scripts. I want it to hold multiple entries with different data types. For instance;
I want a items database script with variables such as Name(string), Max damage(int/float), min damage(int/float), range(int), speed(float), and if its a 2 hander.(bool)
Thanks in advance.
Answer by CHPedersen · May 09, 2011 at 11:15 AM
Are you using Visual Studio as your editor? If yes, Visual Studio has a pretty decent SQL engine and database editor you can use to help you set it up. Try right-clicking on your project solution and selecting "Add new item", then pick "Local Database". Then proceed to add tables and define the columns using the editor.
C# (and .Net in general) has multiple ways to access the newly created database, such as TableAdapters. These are objects that handle the creation of SQL queries for you so you only have to call methods to get them to return data. You can intantiate one pr table in your database, make the TableAdapters public variables of a static class. Then all scripts can access them.
If you don't have Visual Studio, all of this is still possible, just a little more time-consuming to set up because you have to do it manually without a visual editor's help.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Launching local Unity API Reference from MonoDevelop 7 Answers
Error message "variable not assigned" ? 1 Answer
build for iphone - "function is not a member of object" 1 Answer
How to run function in another script with prefabs? C# 2 Answers