George Lucas first wanted to make a Flash Gordon film but couldn't get the rights to it.
He had been brought up on film serials of Flash Gordon, Buck Rogers and also on Western and "Jungle" serials. (He ripped off the latter to create Indiana Jones.)
I was once a huge Star Wars fan. I have analysed Lucas' early draft screenplays for what would have been the first movie. It was more of a collection of loose ideas for various scenes and relationships than a coherent story. Each draft had a very different story but made from the same collection of ideas.
He picked from that big bag of ideas to create the stories for the first three movies, and had to make it up as he went along. There was an idea to give Luke a sister (who was not Leia), but that was scrapped.
He continued go pick from the big bag to make the three prequels, but the overall story had already pretty much been defined by things said in the first trilogy.
The drafts contained also lots of names that he had come up with, but he had used them for wildly different things.
Right before Episode 3 was released, I noted down each idea and name I could find in the old drafts and gave it a checkmark if it was in a released movie (some things in more than one, obviously). The items left without a checkmark corresponded quite well to what happened in Episode 3.
So when Lucas had made six movies, I think he was pretty much out of ideas. He said that there was never going to be any more movie — and none was made until after Disney had bought it.
Some set design in Star Wars shows clear inspiration/homage to Flash Gordon serials, and Lucas originally also wanted the starships to be sleek silver designs reminiscent of those in that serial. He got that wish realised first with CGI starships in the prequels.
Lucas (and his friends Spielberg and Coppola) was a big fan of Akira Kurosawa. The first "Star Wars" is said to also have contained clear inspiration from Kurosawa's "The Hidden Fortress". (princess Leia, two bickering side-characters providing comic relief, reveal at end, "The rebels' hidden fortress").
There was also inspiration from Asimov's Foundation series (smugglers, robots, atomic energy, galactic empire, capitol being a city-planet, "Corellia", "Kessel") and from Dune (spice mines, dune sea).
I find Star Trek the original series to be like it ripped off an existing sci-fi novel in each episode. The starship Enterprise and its crew was there mainly to provide a frame narrative.