Beispiel #1
0
    // Spawned de betreffende objecten.
    public void Spawn(FlockManager fm)
    {
        // Positie van de speler binnen halen..
        Vector3 playerPos = player.transform.position;

        //check in welke layer de speler zwemt.
        if (playerPos.y > 430)                          //flying fish!!!
        {
            return;
        }
        else if (playerPos.y < 160)             //layer 3
        {
            spawnDataIndex = 3;
        }
        else if (playerPos.y < 250)             //layer 2
        {
            spawnDataIndex = 2;
        }
        else if (playerPos.y < 340)             //layer 1
        {
            spawnDataIndex = 1;
        }
        else if (playerPos.y < 430)             //layer 0
        {
            spawnDataIndex = 0;
        }

        // Get random position
        Vector3 randomPos = GetRandomPositionInRange(
            playerPos,
            spawnData[spawnDataIndex].minRange,
            spawnData[spawnDataIndex].maxRange
            );

        //get Y height
        RaycastHit hit;
        Ray        ray = new Ray(new Vector3(randomPos.x, 410f, randomPos.z), Vector3.down);

        if (Physics.Raycast(ray, out hit, 420f))
        {
            randomPos.y = hit.point.y + 20f;
        }

        // set fish tank.
        fm.Spawn(
            spawnData[spawnDataIndex],
            randomPos
            );
    }