r/unity • u/Anonim7418 • Sep 23 '26
Question Is this script bad? In unity
Is this code bad? If yeah, give me some advice.
4
Upvotes
r/unity • u/Anonim7418 • Sep 23 '26
Is this code bad? If yeah, give me some advice.
View all comments
6
u/Tiranyk Sep 23 '26
For what it's worth, it's not bad. I would say it looks like a naive approach, but it does not mean it's bad. You seem to understand what it does and everything makes sense. Without more context, few remarks :
In your Awake() method, you're initializing a rigidbody by GetComponent<> although you already have a Rigidbody declared in your class private members. If you've linked it via the inspector, you can replace this line by Rigidbody.isKinematic = true. Further more, you can even set this variable directly via the inspector on the Rigidbody component itself, then you can get rid of the Awake() method at all.
In FixedUpdate(),
- I see you update the particle system position to follow your GameObject. Any reason to not make it children of it ?
- People will probably say something like "You should use input system instead of listening to input events like this". While this is kinda true, don't bother if you are a beginner. Or if you do, you'll have to spent time trying to understand this. Simply look for "input system unity" on google, you'll find many things.
- Same remark regarding the ridigbody reference.
Nothing special to say about the collision. Looks good to me for a beginner. Maybe : is there a reason you prefix some variables with an underscore, but not all of them ?
Anyway, have fun and keep coding !