#Clean human readable code ready for github push?

1 messages · Page 1 of 1 (latest)

crimson flame
#

anyways, does this code look "clean" and human readable? I'm going to make this open source and I need the code to be ready, this format etc that is used in this script is used in all my scripts so that's why I'm showing specifically this one, so if I made a mistake with like, naming conventions, or readability, I can use that as help to fix the other classes and scripts

#

I think that's right?

calm tangle
#

yep, gimme a sec i’ll hop on my laptop

crimson flame
#

:)

calm tangle
# crimson flame :)

Alright heres some initial impressions:

  1. Do all those variables need to be public?
  2. In the UpgradePlayer method, why dont you use an enum as the parameter instead of a string?
crimson flame
#

I know you can subscribe to another class but I have no idea and haven't found any kind of documentation on how to do that, just heard it thrown around a few times

bronze cargo
#

I think you could start up by breaking classes down? UnityChanThink This class has various responsibility

crimson flame
#

yeah but it controls the player, all aspects of it is still controlling the player so that's why I kept it all in one class.

I could seperate something like upgrades though but most of the other things I think fit into the class

bronze cargo
#

Game pausing, Health management, Weapon management, Cheat, etc.. IMO they should be separated

crimson flame
#

oh?

#

not trying to be dismisive or anything but I thought that Health management and Weapon management would still be part of a players controller?

also pausing already has a seperate script I just forgot to update the code sense I made that new script nf_neko_giggle

#

the cheats are just for debugging but I do think it should be seperate yeah :) thanks for the advice

bronze cargo
#

My impression of term 'controller' is something movement-related, maybe including camera.

Weapons for example you might want different damage mechanism or cooldown mechanism per weapon. Separating class will help you modularizing those.

#

For health management, separating class lets you reuse same logic to non-players, monsters for example.

crimson flame
#

hmm, okay, I'll try seperating them them Koharu_think

also I was thinking of controller more like something that controls the players data :)

crimson flame
bronze cargo
#

Clean-up wise I see some inconsistent SerializeField and capitalization. And the switch-case has some common code you might want to combine..

calm tangle
#

I really mostly have minor things left:

  1. Line 116 HealthHandler healthbar = gameObject.GetComponent<HealthHandler>(); you should cache this. Same with line 119
  2. Inside the shoot method, you can avoid the bullet get component by instantiating the bullet component instead of the game object. It will still spawn the bullet gameobject but returns the component
[SerializeField] private Bullet bullet;
// method
CanShoot = false;
Bullet I = Instantiate(bullet, spawnLocation.position, spawnLocation.rotation);
I.damage = PlayerStats.ATK;
Destroy(I.gameObject, 1);
crimson flame
crimson flame
#

I've never heard of caching something before

calm tangle
crimson flame
#

like where I don't re-asign it

calm tangle
#

yep