Public variable works perfectly fine for me, and it should even be able to be tweaked by anything in the scene that needs to, so if anything this should work better.
It depends on the circumstances to what’s required.
Public variables work until they get you into a situation where they get you into trouble.
even be able to be tweaked by anything in the scene that needs to
Interestingly this is one of the reasons why you shouldn’t always use it.
Many people do though, infact most people I see use public variables instead of SerializeField, recently I did the Unity Begineer course and they’ve only talked about public also.
In any case, the reasoning comes into safety and readability. If I see someone elses code, I should be able to see the variables at the top and know “the ones with public is being used/tweaked elsewhere” and “the ones with SerializeField means likely variables are being updated/changed in the editor” without having to look over ALL your code.
You might also have names that are similar, or code you don’t want tweaked and you want to ensure it won’t be able to, either through other peoples codes, or yourself accidentally. It also helps in debugging your code as well.
Public variable also makes the variable accessible by other scripts which u don’t want in some scenarios
while [SerializeField] keeps the variable Private while making it visible on the Inspector window
You can also hide Public variables from the inspector using [HideInInspector], it’s absolutely fine to never need/use any of these, but the option to do so is there anyway, and that’s what I like about programming, there’s always different ways to achieve the same result
Public variables seem harmless enough when used in a small project but can make the code difficult to read and introduce bugs in a large codebase. The problem is that because any other script can tweak those values you can have very strange behaviour - such as a class that is responsible for managing the levels perhaps, which is tweaking values on the car class. Now if you’re trying to debug something on that car class, you’ve got no way of knowing that one of the values is being modified elsewhere.
When the variable is kept private, you can track exactly how and when it is being modified. This practice also encourages classes to have a clearly defined responsibility which makes the code easier to understand and modify as it gets more complex.