Would the whole world unite if there was a threat from another planet? Is that the only thing that will bring us together as a species?

Let us imagine that there was a threat from another planet. Would humanity be able to put aside our differences for the sake of thwarting an enemy attack? There would be no time for infighting when the survival of not just one nation, but all nations is at stake. I think it is safe to say, that with a few fanatical exceptions, humanity would unite long enough to fend off the otherworldly enemy, but that as soon as the mission was near completion. the divisions would begin again.

One author that examined what might happen in this situation in exquisite detail is Orson Scott Card in his Ender's Shadow Series.

**Spoiler**

The series shows what would happen if Earth was scourged by an alien species and anticipating another attack. In the series the world unites, but when victory is assured it begins splintering and the world is launched into a fourth world war.

The key is that while the world was united against the alien menace they had to appoint leaders so that they could be well coordinated (every group needs a leader). They appointed three top leaders: The Polemarch, The Strategos, The Hegemon. These three people were the three most powerful people in the whole world. When humanity began to split one The Hegemon started a campaign to unite the world under one rule. He saw that humanity's survival is linked to Earth's. He wanted to ensure that if any other alien civilization met humanity they could not destroy the whole species by simply destroying the planet. It was the legitimacy given to his position by all of humanity that allowed him to gain support.

The only reason The Hegemon was able to unite the world was because during the first alien invasion his position was created by ALL of humanity and so he had legitimacy as the ruler of all humanity. In the series he unites the world and sends hundreds of colony ships to other worlds, and thus humanity expands to to all reaches of the known universe.