Esempio n. 1
0
        /// <summary>
        /// Generate some additional gameobjects to the inside of a cell
        /// </summary>
        private void GenerateObjectsInCell(DistrictCell cell)
        {
            //using an inset create a smaller cell from the cell
            //this is to avoid spawning objects on buildings or roads
            var insetCell = cell.Inset(_terrainSettings.RoadWidth/2);

            var amount = _terrainSettings.AdditionalProps;

            //Generate the spawn points inside the cell
            var points = insetCell.GenerateRandomPoints(Random.Range(amount - 5, amount + 5));

            foreach (var p in points)
            {
                //create a 3D vector from the 2D point
                var position = p.ToVector3();

                //randomize what will spawn
                var r = Random.value;

                //spawn a tree
                if (r < 0.75)
                {
                    SpawnTree(position);
                }
                else if(r < 0.85f) //Spawn a prop
                {
                    SpawnProp(position);
                }
                else
                {
                    //nothing
                }
            }
        }