Example #1
0
    void GenerateProps(PartySettings settings)
    {
        // Generate required props
        foreach (GameObject g in settings.requiredProps)
        {
            PartyProp prop = g.GetComponent <PartyProp>().Spawn();
        }

        int propCount = settings.GeneratePropCount();
        List <GameObject> possibleProps = settings.GetRandomProps(propCount);

        for (int i = 0; i < propCount; i++)
        {
            PartyProp prop = possibleProps[i].GetComponent <PartyProp>().Spawn();
            if (prop)
            {
                //props.Add(prop);
            }

            /*
             * GameObject partyGoerPrefab = Util.RandomSelection<GameObject>(possiblePartyGoers, p => settings.DancerWeight(possiblePartyGoers.IndexOf(p)));
             * SpawnPartyGoer(partyGoerPrefab);
             */
        }
    }
Example #2
0
    public PartyProp Spawn()
    {
        PartyProp prop = Instantiate(gameObject, GetSpawnVector(), transform.rotation).GetComponent <PartyProp>();

        if (prop.rb)
        {
            RaycastHit[] hits  = prop.rb.SweepTestAll(Vector3.up, 0.1f);
            int          tries = 4;

            while (hits.Any(h => h.collider.GetComponent <PartyProp>()))
            {
                prop.transform.position = GetSpawnVector();
                hits = prop.rb.SweepTestAll(Vector3.up, 0.1f);
                tries--;
                if (tries == 0)
                {
                    Destroy(prop.gameObject);
                    return(null);
                }
            }
        }
        return(prop);
    }