Esempio n. 1
0
    public void updatePopulation()
    {
        //if number fish in our species is less than the number the model provided
        if (population < m_targetNumber)
        {
            //find how many fish we are off by
            int popDifference = m_targetNumber - population;

            //and create that many fish
            for (int y = 0; y < popDifference; y++)
            {
                FlockAgent newAgent = Instantiate(
                    m_FlockAgent,
                    m_AIManager.RandomPosition(),
                    Quaternion.Euler(UnityEngine.Random.Range(-20, 20), UnityEngine.Random.Range(0, 360), 0),
                    transform);
                newAgent.name = "Agent " + agents.Count;
                newAgent.Initialize(this);
                agents.Add(newAgent);
            }
        }
        //or we remove fish as long as we have too many
        else
        {
            while (population > m_targetNumber)
            {
                var target = m_FlockAgent.GetComponentInChildren <Transform>();
                Destroy(target.GetChild(target.childCount - 1).gameObject); // kill youngest child
                agents.RemoveAt(target.childCount - 1);
            }
        }
    }
Esempio n. 2
0
 Vector3 GetWaypoint(bool isRandom)
 {
     if (isRandom)
     {
         return(m_AiManager.RandomPosition());
     }
     else
     {
         return(m_AiManager.RandomWaypoint());
     }
 }