Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        framecount++;

        //
        if ((framecount % 10 != 0 || (thingsSpawned.Count > maxToSpawnInBiome * 4)) && portal.activeInHierarchy)
        {
            return;
        }

        Random.seed = (int)(Time.deltaTime * 1000);

        //A Random Point in your Camera View Port
        Vector3 ranPt = new Vector3(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), backCam.nearClipPlane);
        //The World Point you see thru camera
        Vector3 startpt = backCam.ViewportToWorldPoint(ranPt);
        //The Direction vector from Camera to start point
        Vector3 dir = startpt - backCam.transform.position;
        Vector3 pos = new Vector3(), normal = new Vector3();

        if (vxe.RayCast(startpt, dir, 64, ref pos, ref normal))
        {
            //SPAWN PORTAL:*********************************************************************
            //If the portal is not active, try spawning one
            if (!portal.activeInHierarchy)
            {
                spawnPortal(pos, 0.6f, chunkFloorPos.y);
            }

            ///SPAWNING FOR ANIMALS*********************************************************************
            //Convert the voxel position into a Chunk World Position
            Vec3Int chunkcoord = vxe.ToGrid(pos) / vxe.chunk_size;

            //Loads up the BiomeMap through the grid size
            BIOMES mybiome = biome.biomeMap [chunkcoord.x, chunkcoord.z];

            //If there are too many spawns in this Biome, do not spawn more
            if (spawnCountInBoime [(int)mybiome] > maxToSpawnInBiome)
            {
                return;
            }

            //randomly chooses an animal to spawn
            int        animalIndex = Random.Range(0, spawnTable [mybiome].SpawnList.Length);
            GameObject spawnObject = spawnTable [mybiome].SpawnList [animalIndex].gameObject;

            Chunks chunk     = vxe.getChunkFromPt(pos);
            bool   isSurface = vxe.isChunkASurface(DIR.DIR_UP, chunk, .65f);

            if (spawnTable [mybiome].SpawnList [animalIndex].sticksToWalls || isSurface)               // Vector3.Dot (normal, Vector3.up) > 0.999f) {
            {
                GameObject newsphere = (GameObject)Instantiate(spawnObject, pos + normal * VoxelExtractionPointCloud.Instance.voxel_size * 0.5f, Quaternion.identity);
                newsphere.SetActive(true);
                //SimpleAI ai = newsphere.GetComponent<SimpleAI> ();
                thingsSpawned.Add(newsphere);
                //newsphere.GetComponent<GrowScript>().init(pos, normal, (Vector3.Dot (normal,Vector3.up) > 0.999f) );

                spawnCountInBoime [(int)mybiome]++;
            }
        }
    }