/// <summary>
        /// Finds all as spawn tagged objects and fills the molecule queue of the attached collector with molecules
        /// for the start.
        /// </summary>
        void Start()
        {
            collector       = GetComponent <CoolingCollectorScript>();
            moleculeManager = GameObject.Find("CoolingGameManager").GetComponent <CoolingMoleculeManager>();
            // Find all as spawn tagged objects
            spawnPositions = ExtensionMethods.FindComponentsInChildrenWithTag <Component>(gameObject, "Cooling.Spawn");

            if (collector && prefabObject && waypoints.Length > 0)
            {
                for (int i = 0; i < 10; i++)
                {
                    CWater clone = Instantiate(prefabObject);
                    // Wapoint doesnt matter, gets overwritten later, and index 0 is always available
                    clone.waypoint = waypoints[0];
                    moleculeManager.AddMoleculeToList(clone);
                    clone.gameObject.SetActive(false);
                    collector.moleculeQueue.Enqueue(clone);
                }
            }

            if (spawnPositions.Length > 1)
            {
                singlespawn = false;
            }
        }
        /// <summary>
        /// Adds a new molecule (CWater instance) to the attached collector molecule queue
        /// </summary>
        public void AddMoleculeToQueue()
        {
            CWater clone = Instantiate(prefabObject);

            clone.waypoint = waypoints[0];
            moleculeManager.AddMoleculeToList(clone);
            clone.gameObject.SetActive(false);
            collector.moleculeQueue.Enqueue(clone);
        }
        /// <summary>
        /// On each frame molecules are spawned according to the spawn timer, unless the
        /// queue is empty. Each molecule gets a spawnpoint that is randomly modified within a
        /// certain factor. Also its temperature is changed and a new waypoint is attached.
        /// In the end it is set active, while in queue all molecules are inactive.
        /// </summary>
        void Update()
        {
            timerMolecules += Time.deltaTime;
            if (collector.moleculeQueue.Count > 0 && timerMolecules > rateMoleculeSpawn)
            {
                CWater  spawnMolecule = collector.moleculeQueue.Dequeue();
                float   randomY       = UnityEngine.Random.Range(-(SPAWNAREA), SPAWNAREA);
                float   randomZ       = UnityEngine.Random.Range(-(SPAWNAREA), SPAWNAREA);
                Vector3 spawnPos      = GetSpawnPosition();
                spawnPos.y += randomY;
                spawnPos.z += randomZ;
                spawnMolecule.transform.position = spawnPos;
                spawnMolecule.ChangeTemperatur(temperatureAmount);
                if (floatingText)
                {
                    ShowFloatingText(temperatureAmount);
                }
                spawnMolecule.waypoint = GetWaypoint();;
                spawnMolecule.gameObject.SetActive(true);

                timerMolecules -= rateMoleculeSpawn;
            }
        }
Пример #4
0
 /// <summary>
 /// Called by SpawnScript
 /// </summary>
 /// <param name="_Molecule">New molecule</param>
 public void AddMoleculeToList(CWater _Molecule)
 {
     moleculeList.Add(_Molecule);
 }