Ejemplo n.º 1
0
    void SpawnWhale()
    {
        const float minWhaleDist    = 40.0f;
        const float minBoatDist     = 40.0f;
        const float minWhaleDistSqr = minWhaleDist * minWhaleDist;
        int         maxTryCount     = 30;
        int         tryCount        = 0;

        Vector3 pos;
        Vector3 posRight;
        Vector3 posLeft;
        Vector3 posUp;
        Vector3 posDown;

        do
        {
            if (tryCount > maxTryCount)
            {
                return;
            }

            pos = new Vector3(
                Random.Range(-c_map_width / 2, c_map_width / 2),
                c_whale_y,
                Random.Range(-c_map_height / 2, c_map_height / 2)
                );
            tryCount++;

            posRight = pos + new Vector3(10.0f, 0.0f, 0.0f);
            posLeft  = pos + new Vector3(-4.0f, 0.0f, 0.0f);
            posUp    = pos + new Vector3(0.0f, 0.0f, 5.0f);
            posDown  = pos + new Vector3(0.0f, 0.0f, -5.0f);
        }while (
            m_TerrainBuilder.SampleHeightDataWorld(pos.x, pos.z) > 60 ||
            m_TerrainBuilder.SampleHeightDataWorld(posRight.x, posRight.z) > 60 ||
            m_TerrainBuilder.SampleHeightDataWorld(posLeft.x, posLeft.z) > 60 ||
            m_TerrainBuilder.SampleHeightDataWorld(posUp.x, posUp.z) > 60 ||
            m_TerrainBuilder.SampleHeightDataWorld(posDown.x, posDown.z) > 60 ||
            ClosestWhaleDistSqr(pos) < minWhaleDistSqr ||
            m_BoatManager.BoatInRegion(pos, minBoatDist)
            );

        GameObject whale = GameObject.Instantiate(m_Whale);

        whale.transform.SetParent(transform);
        whale.transform.position = pos;
        whale.transform.LookAt(pos + new Vector3(1.0f, 0.0f, 0.0f));

        Whale whaleComp = whale.GetComponent <Whale>();

        whaleComp.m_SpawnLocation = pos;

        m_whaleList.Add(whale);
    }
Ejemplo n.º 2
0
    void SpawnFish()
    {
        Vector3 pos;

        do
        {
            pos = new Vector3(
                Random.Range(c_fish_bounds.xMin, c_fish_bounds.xMax),
                c_fish_y,
                Random.Range(c_fish_bounds.yMin, c_fish_bounds.yMax)
                );
        }while (m_TerrainBuilder.SampleHeightDataWorld(pos.x, pos.z) > 110);

        float   angle = Random.Range(0, 2 * Mathf.PI);
        Vector3 vel   = new Vector3(
            Mathf.Cos(angle) * c_fish_speed,
            0.0f,
            Mathf.Sin(angle) * c_fish_speed
            );

        GameObject fish = GameObject.Instantiate(m_Fish);

        fish.transform.SetParent(transform);
        fish.transform.position = pos;

        FishData fishData = new FishData();

        fishData.m_fish     = fish;
        fishData.m_velocity = vel;
        m_fishList.Add(fishData);
    }