Luigi in general suffers from good projectile zoning. He's incredibly powerful once he gets in but doesn't have great approach tools.
To win against Mega Man, you need to have a good punish game. Be aware of the ending lag on his projectiles. As Kel mentioned, the lemons can be punished, especially if Mega Man runs out of stage to work with. Since Mega Man still has free movement with walking and jumping even during the "endlag," try to cover where he might jump with an aerial. It isn't as easy as Kel makes it out to be, especially if he's moving away from you. In order to get him into a position where you can effectively punish it, try to pressure him towards the edge of the stage. You might not be able to directly approach but by running up and shielding or rolling, he may continue to do retreating lemons to keep you out. Just be aware of the possibility for a grab mix up on your shield. Metal Blade is unsafe on shield if used too close, as is the Crash Bomb.
Because of this, it is wise to take Mega Man to the smallest stage that he has not banned. Don't try to fight him on FD or Town and City.
Once you do have him on the edge, know his escape options. Low level or panicked players will often try to roll towards the stage. I do not know what Luigi likes to punish rolls with, but I'm certain you do.
A better Mega Man will vary the way he regains his space. Sometimes he will attack you with a down tilt (which you can shield to punish), sometimes he will try to shoot more projectiles, (which you can punish if you're close enough). He may try to jump over you, with or without an airdodge, or even simply run back to the stage. He might grab you once you get close and back throw you away to regain control, or run up to you and try to grab you. It's up to you to observe the situation + his previous patterns and decide what will allow you to keep control.
In my experience, the most common thing Mega Man will do is try to grab you and back throw you if he isn't the rolling kind. This gains him stage control and leaves him in a position where he can try to gimp you. Prepare for this the most. Shooting him with a fireball combos into grab, if I'm not mistaken?
All of this assumes that Mega Man is only trying to zone you out with projectiles. This is Mega Man's main goal in the MU as he wants to stay clear of your grab combos. However, be aware that it is not all that he will try to do. A good Mega Man will come in to grab you if he sees a hole in your defense, especially below kill percent.
Whatever you do, try not to get hit by the Metal Blade (buzz saw); It confirms into grab at mid and high percents thrown raw and almost any percent if tossed as an item.
Lastly, it's important to know that Mega Man's kill moves are more situational than some and very punishable if they miss. If you are at kill percent and trying to land, odds are he will try to up smash you. If he catches you rolling, you might be eating a down smash (do not roll behind him when you are at kill percent for down smash). F-smash can trap your landing well if you use your double jump, so try to conserve it if you can. U-tilt is generally only a threat on a hard read, but if you do a neutral air onto his shield, he can punish you with u-tilt out of it. U-tilt also true combos out of a diagonal Metal Blade, so watch out if he's at about a 45 degree angle from you in the air.