Hello everyone. This is my first time on the forums so I hope I am in the right place for this. Anyways I have an idea im trying to figure out how to implement into a game. Its probably a really simple solution that I might be searching wrong for.
Anyways what I am trying to do is create a UI that is interactable and it shows variables from the components in the editor. I dont want to show everything though, just select parts. Also the project idea is an FPS with a custom bullet editor. Something similar to God Eater, or Ballistic Craft. I want to show things like Bullet speed, bouncyness, stickyness, Element type, editable trajectory paths, Rate of fire (set to a limit that aint too crazy), and I think thats all I want editable by the player for now.
Also not sure if this is relevant information, but the guns are going to be customizable as well so that you can combine stocks, mags, bodies, barrels, optics, and accessories to make your gun on top of the bullet editor that I want to do.
Not looking for a code hand out, just a point in the right direction as tutorials go. Or what im supposed to search for as my goggle skills suck. If you want to post code im fine with that too but i would like to learn from a tutorial if possible. Also, am I in the right train of thought as how I want to do this system? Is there an easier better method im not seeing or thinking about? Work smarter not harder is what i tend to go by so yeah lol.
Thank you in advance for the help if anyone is able to help. And sorry in advance if this is in the wrong location on the forums.
As far as your display/edit functionality, that sounds like basic UI stuff. It is often recommended to keep the functionality of a system, and the display of information to the user about that system separated. So for editing a bullet, I’d have your bullet script but expose either public fields to modify the bullet, or public methods if more work needs to be done with an edit. Then you have some other script that handles the UI with a reference to the bullet script and the relevant UI references. That can be to a UI.Text, maybe an input field, or a slider. You might use TextMeshPro which works similarly after you go through the steps of getting it all set up.
When you use input fields, then you need to parse the string the player enters and convert that into the appropriate numeric type (int, float, etc). You also need to clean up or verify the input. For example, if the player enters a weight of the bullet measured in grains, you’ll probably want to not allow negative values even though they are valid integers. Though the effects of a bullet with negative mass would be interesting
Using a slider or other type of UI element which doesn’t directly take a string you need to parse, can be simpler in some ways.
To convert a string to an int, I usually use TryParse
Once you have the values from the player, you can then update the values on the bullet script. You can do that as soon as the player enters it, or you could have a button the player presses when they are all done with edits. Either way they use events on the various UI components to call one or more methods in your script. See any UI tutorial which goes into buttons and input fields, etc.
If you want this to persist, for small stuff you can use PlayerPrefs. When things get more complicated you’ll usually write to your own file. JSON is often recommended because it does a lot of the serialize/deserialize work for you. Unity though does support all the regular C# file read/write functionality, so you can write it anyway you want. Save/load functionality is a complicated topic, and there’s lots of threads on it if you want more info.
Thank you for the speedy reply. I will try looking for some UI tutorials again for a refresher. I tend to work a bit on and off so I tend to forget stuff over time. I will also look into the TryParse as well. Thank you again for the reply 
1 Like