If someone is carjacking you and you are in danger then yes you can shoot the carjacker.
If someone is trying to carjack you then they likely are wanting to do harm and they may be carrying a gun or knife themselves and would use it to steal your car.
So if someone tries to carjack you and has a gun pointed at you then if possible you can and should shoot them but if you are inside the car and they are outside the car and are holding a knife at you then you should try to speed off.
Even if the carjacker is holding onto the car try to speed off first and get away.
Your first option should be to try to get away from the danger and not have to shoot the carjacker.
But if you have no other choice and the carjacker is inside your car or has his or her arm in your car trying to attack you then you could shoot them.
But if someone is simply stealing your car or breaking into your car without you in or near it then you cannot shoot them and should just call the police.