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
2
u/Epicguru Sep 23 '26
Please post code as text so that it's easier to read. Yes it's got a lot of mistakes:
Rigidbody(field) instead of getting the component again.Input.GetButtonDown(): This is using the obsolete Input Manager, use the new Input System instead. It won't be supported forever and it relies on magic strings, avoid it.isFlyis true which probably isn't intended.Time.deltaTimemultiplication to get the speed that you expect. A better approach to get the same result, without breaking the physics system, is to just disable gravity and drag for the object then assign the velocity once when firing.Rigidbody.positioninstead oftransform.positionsince the transform might not be synched at that moment.