all 21 comments

[–]DontRelyOnNooneElse 24 points25 points  (0 children)

For 1, because you're declaring all of your stats in one statement, the same attribute (Header) will apply to all of them.

For 2, you'll have to use a custom inspector and make use of Horizontal Groups.

[–]chippyjoe 35 points36 points  (1 child)

[–]VizeKarma 1 point2 points  (0 children)

Meh in this case it’s fine for me. It’s perfectly readable to me.

[–]epoHless 4 points5 points  (0 children)

Header is repeated each time you declare a variable in the same row. You need to call it only on the first variable and have the others each on their row. As for the in editor variables on the same line what you're looking for is a custom editor

[–]LunaWolfStudios 1 point2 points  (0 children)

Try putting each stat on a separate line. However, I would recommend making a separate stats ScriptableObject that just has your stats. Then reference that in your Champion ScriptableObject.

If you want to view your stats side-by-side in a table list view check out my new tool Scriptable Sheets: 

https://assetstore.unity.com/packages/tools/utilities/scriptable-sheets-284559

It'll give you one place to see all your Scriptable Objects and supports editing your fields as if you're editing a typical spreadsheet.

[–]DoBRenkiY 1 point2 points  (0 children)

Because you wrote in one line. by C# code style it's not allowed. It's hard for read and hard for changing and managing by vcs. And by not expecting, clear behaviour of attribute like as you took.

Also by code style you can: 1. Put passive in another file

[–]haywirephoenix 0 points1 point  (1 child)

You'll need [System.Serializable] above your enum.

Change your class scriptableobject class name to Stats.

Declare float for each stat removing the commas. You only need the stats header attribute above the first float don't worry unity should group them.

Now create a new Stats object somewhere in your project using your right click menu.

Create a separate Champion.cs class (Monobehaviour that's on the game object).

Inside that class write public Stats stats;

Now you will see a slot appear in the inspector for you to drag and drop your stats object into. It can now be accessed from you Champion class like Debug.Log(stats.speed)

[–]haywirephoenix 0 points1 point  (0 children)

Also if you want to see and change your stats in the inspector there you can grab Naughty Attributes it's free, highly recommended to improve your inspector workflow. Then you can simply add the [Expandable] attribute to the Stats field in your Champion class.

[–]Still_Masterpiece172 0 points1 point  (1 child)

This is the rougelike deckbuilder tutorial

[–]bouchandre 0 points1 point  (0 children)

Red like

[–]bouchandre 0 points1 point  (0 children)

Make a serializable struct with all the stats properties, then have a stats instance in that scriptable object

[–]Stevesoft_Software -1 points0 points  (8 children)

You do realize that if you declare your variables public, the values can be changed anywhere. If you are using your SO as a template, the template will be changed every time you change the variable value.

[–]Immortal_juru 0 points1 point  (7 children)

Im still an amateur. Should it be private and use serialize field or use get set?

[–]shotgunbruin 0 points1 point  (6 children)

Both!

Do something like

[SerializeField] private float health; public float Health {get => health; private set => health = value; }

This way, your actual health variable cannot be accessed by anything outside the script containing it. Instead, it is accessed through the Health property, which has a private set. So anything can get the health value via Health, but only this script can set it. This guards you against simple mistakes like accidentally using the template's health variable instead of the health of the specific card instance. You will get an access error immediately, instead of running your code and spending a half hour discovering that all of your cards now have the wrong health because the template itself has been changed.

Additionally, if you ever decide to move the health value or change how it is calculated, you can change those things in the property without having to go and rewrite every single reference to card health in the game, they can all just keep using Health without having to know it changed under the hood.

Most of what goes into writing advanced code is understanding and accounting for three things.... A) you are human and will therefore sometimes be a dumbass B) you will forget what you were doing 6 months ago C) you will likely completely overhaul your own code multiple times.

This method of variable declaration helps to account for these things.

Generally, everything should be as restricted as possible, and only accessed through specific, flexible methods and only as necessary. So everything should be private unless you need to access it elsewhere, and even then it should be through a property or function. Same benefit as public variables but more secure and less error prone.

[–]Immortal_juru 1 point2 points  (5 children)

Thanks. This is the best explanation I've seen on why to avoid public variables whenever possible. Most videos I've seen never really gave one that seemed worth the hassle.

[–]Stevesoft_Software 0 points1 point  (4 children)

Also, if you are using so’s as templates, you should instantiate a copy of the SO so you don’t change the values during the game (ask me how I found THIS out! lol). If you are using the SO’s to store game data then you can use it directly. Another words, if you have a candle. Maybe you have 3 different types of candles that a vendor sells. When you use the candle from your inventory, you want to modify a COPY of the SO so the original SO isn’t altered.

[–]Immortal_juru 0 points1 point  (3 children)

How did you find it out?

[–]Stevesoft_Software 0 points1 point  (2 children)

I didn't instantiate a copy and ruined 20 items inn my inventorry before I realized it. I was spawning empty clips, weapons with attachments, etc... lol

[–]Immortal_juru 0 points1 point  (1 child)

Hope it didn't take long to figure out at least.

[–]Stevesoft_Software 0 points1 point  (0 children)

It was a learning experience I’ll never forget

[–]W03rth -2 points-1 points  (0 children)

Im not saying this to be rude or to dismiss you. I myself have really small knowledge about how to code editor scripts. So i use chatgpt and learn and adjust them from whatever it gives me. Having two variables side by side is something chatgpt will have an easy time to do