/// <summary>
        /// Destroy all objects in the area (that belongs to this script) and creates them again.
        /// The list of newly created objects is returned.
        /// </summary>
        /// <returns></returns>
        public void RegenerateObjects()
        {
            for (int i = transform.childCount - 1; i >= 0; --i)
            {
                DestroyImmediate(transform.GetChild(i).gameObject);
            }

            for (uint i = 0; i < count; i++)
            {
                GameObject created = Instantiate(gameObjectToBeCreated[Random.Range(0, gameObjectToBeCreated.Length)],
                                                 GenerateUtils.GetRandomPositionInWorldBounds(_bounds), GenerateUtils.GetRandomRotation(randomRotationMinimal, randomRotationMaximal));
                created.transform.parent = transform;
            }
        }
예제 #2
0
        /// <summary>
        /// Destroy all agents in the area (that belongs to this script) and creates them again.
        /// The list of newly created objects is returned.
        /// </summary>
        /// <returns></returns>
        public List <AgentLogic> RegenerateObjects()
        {
            for (int i = transform.childCount - 1; i >= 0; --i)
            {
                DestroyImmediate(transform.GetChild(i).gameObject);
            }

            _activeAgents = new List <AgentLogic>();
            for (uint i = 0; i < count; i++)
            {
                AgentLogic created = Instantiate <AgentLogic>(agentsToBeCreated[Random.Range(0, agentsToBeCreated.Length)],
                                                              GenerateUtils.GetRandomPositionInWorldBounds(_bounds), GenerateUtils.GetRandomRotation(randomRotationMinimal, randomRotationMaximal));
                created.transform.parent = transform;
                _activeAgents.Add(created);
            }

            return(_activeAgents);
        }