Exemplo n.º 1
0
    private void IncreaseVelocity(int p)
    {
        if (m_molecules == null || m_molecules.Count < 1)
        {
            Debug.LogError("Failed to clear. No Molecules found");
            return;
        }

        for (int i = 0; i < m_molecules.Count; i++)
        {
            m_gasMovementScript = (MoleculeMovement)m_molecules[i].GetComponent(typeof(MoleculeMovement));

            if (m_gasMovementScript != null)
                m_gasMovementScript.SetSpeed(p);
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// This displays the water or vapour molecule depending upon the flag isVapour
    /// </summary>
    /// <param name="isVapour"></param>
    public void ShowMolecule(bool isVapour)
    {
        if(m_snowBall == null)
        {
            Debug.LogError("ERROR - NO SNOW BALL FOUND");
            return;
        }

        if (!m_hot && !m_hotSpotWater)
        {
            Debug.LogError("No vapours found. Please click on hot button to generate vapours");
            return;
        }

        //CleanSpace();

        int numberOfMolecules = 0;

        float speed = 0;
        float drag = 0;
        int maxMolecules = 0;

        if (isVapour)
        {
            // Set the speed of molecule to the speed of vapour molecule
            speed = VapourMoleculeSpeed;

            // Set the drag factor
            drag = 0.2f;

            // Set the max number of molecules
            maxMolecules = MaxVapourMolecules;
        }
        else
        {
            // Set the speed of molecule to the speed of water molecule
            speed = WaterMoleculeSpeed;

            // Set the Drag factor
            drag = 1.8f;

            // Set the number of molecules to twice as much as vapour molecule
            maxMolecules = 2 * MaxVapourMolecules;
        }

        // Helper vector to vary the instantiation position of molecules
        Vector3 temp = new Vector3();

        while (numberOfMolecules++ < maxMolecules)
        {
            GameObject molecule = null;

            try
            {
                molecule = (GameObject)Instantiate(Resources.Load("Molecule"), Vector3.zero, Quaternion.identity);
                molecule.rigidbody.drag = drag;
            }
            catch (Exception e)
            {
                Debug.LogError("Failed To instantiate molecule");
                return;
            }

            // Set snow ball as parent of molecule
            molecule.transform.parent = m_snowBall.transform;

            // set temp as center of snow ball
            temp = m_snowBall.transform.position;

            // get a random offset for temp
            temp.x += UnityEngine.Random.Range(-4, 4);
            temp.z += UnityEngine.Random.Range(-4, 4);
            temp.y += UnityEngine.Random.Range(-4, 4);

            //molecule.transform.position = m_snowBall.transform.position;
            molecule.transform.position = temp;

            // add the molecule to list of molecules
            m_molecules.Add(molecule);
        }

        // set speed of each moelcule
        foreach (GameObject molecule in m_molecules)
        {
            m_moleculeMovement = (MoleculeMovement)molecule.GetComponent(typeof(MoleculeMovement));

            if (m_moleculeMovement != null)
                m_moleculeMovement.SetSpeed(speed);
        }
    }