The idea of south-slavic unity predates the state by quite a bit. It was in some ways present at least from early 19th century as an integral part of national movements, especially in Austro-Hungarian lands, Slovenia and Croatia. It developed into a somewhat more coherent political option in late 19th century. However, there was no clear proposals and also no coherence between Yugoslav ideas in south Slavic parts of Austria-Hungary and by than independent ex-parts of Ottoman Empire, Serbia being by far the most important among latter.
However hazy, an idea of Yugoslavia was there, and at the end of the First world war, as Austria-Hungary was falling apart it got ever more traction. However, two parts that will join to form the Kingdom had quite different starting positions and very ideas of what it was supposed to be.
Serbia, even though occupied from 1915 did end up at a victorious side of the war, large parts of its army were preserved at Corfu, and new constitutes around ThessalonĂki, from where Serbia was liberated with the breakthrough on the oft forgotten southern front of the First world war. By 1918 there seemed to be basically two options open to Belgrade: expansion of Kingdom of Serbia to Serb majority areas in Bosnia and probable incorporation of Macedonia or unification with south Slav regions into a new, larger Kingdom.
South Slav lands of Austria-Hungary (Slovenia, Croatia, Bosnia and Hercegovina) had a bit more complicated situation. Not only were they on the losing side of the war, but also the imperial system of Austro-Hungary was quickly falling apart. One possibility, hardly and option, was to form independent national states, but that implied great territorial loses as Italy was already occupying east Adriatic coast, Serbia into Bosnia from the East, etc. Also, there were large internal unrests, with large number of armed deserters and demobilized soldiers, so called green cadre. They themselves had some, incoherent social element, expressed through plunder of large landholdings and property of nobles. That dimension was starkly brought home with the socialist revolt in the fleet at Kotor.
So, the ex Austro-Hungarian south Slavic lands formed a short lived State of Slovens, Croats and Serbs, with the express intention of unification with Kingdom of Serbia and Montenegro. That offered a out from myriad of problems: Serbia had an army that could at once check the Italian expansion and internal unrests, and it would mean switching to the winning side in the war even after the war was concluded, which would also make the Italian expansion clearly illegitimate.
As time was short, mentioned State of Slovenes, Croats and Serbs existed for just a month, the hazy idea of what south Slavic unity would be flowed into a hazy unification into Kingdom of Serbs, Croats and Slovenes (later renamed Kingdom of Yugoslavia). The unification was proclaimed on 1st December 1918, with question about its form, would it be centralized or federation etc. were left for later time after immediate worried with internal unrests and Italian expansion were settled.