This is a tricky one and you will hear advice about taking different amounts of sand, hit closer to the ball etc
But this is the hard way and you should leave this method to the pros as it requires too much skill to judge how close to the ball to hit and is really too hard for the average golfer.
The simplest way to vary the distance in the bunker is to vary the length of your backswing.
Keep the backswing short for the small ones (still accelerate through the shot) and use a longer fuller swing for the longer ones,
Generally you should use your sand wedge (54 – 56 degrees)
But you can also vary the distance you hit you bunker shots by changing your club, use your lob wedge (60 degree) for the short ones where the pin is up close and you can also use your pitching wedge for the ones that are further away and you need some distance and/or some run if the flag is back.
Make sure you accelerate through all your bunker shots and follow through to a full finish position, tummy to the target and right heel up off the ground, you must commit to the shot and be confident.