Пример #1
0
    // Update is called once per frame
    void Update()
    {
        // Update mass label
        int mass = atomicScript.getAtomicMass();

        massLabel.text = mass.ToString();

        // Update charge label
        int    charge = atomicScript.getCharge();
        string sign   = "";

        if (charge < 0)
        {
            sign = "-";
        }
        else if (charge > 0)
        {
            sign = "+";
        }
        charge = Math.Abs(charge);

        chargeLabel.text = sign + charge.ToString();

        // Update number of protons
        int protons = atomicScript.getAtomicNumber();

        numProtonsLabel.text = protons.ToString();

        // Update name of element
        element.text = elementsName[protons];
    }
Пример #2
0
    void OnTriggerStay(Collider collision)
    {
        if (!(collision.gameObject.name.Contains("electron") || collision.gameObject.name.Contains("proton") || collision.gameObject.name.Contains("neutron")))
        {
            return;
        }
        FixedJoint joint = collision.gameObject.GetComponent <FixedJoint>();

        if (joint)
        {
            return;
        }
        if (isColliding)
        {
            return;
        }
        isColliding = true;

        if (collision.gameObject.name.Contains("electron"))
        {
            int n = atomicScript.getElectronCount();

            // If electron total is already max (10)
            if (n == 10)
            {
                GameObject.Find("Error").GetComponent <ErrorSound>().playError();
            }
            else
            {
                Vector3 destination = atomicScript.getElectronPosition(n + 1);
                lerpParticle(collision.gameObject, destination);
                atomicScript.addElectron();

                collision.gameObject.SetActive(false);
                collision.gameObject.GetComponent <StartingPosition>().ResetToSpawn();
                collision.gameObject.SetActive(true);

                GameObject.Find("Popping").GetComponent <PoppingSound>().playPop();
                return;
            }
        }
        if (collision.gameObject.name.Contains("neutron"))
        {
            int n = atomicScript.getNeutronCount();

            // If neutron total is already max (10)
            if (n == 10)
            {
                GameObject.Find("Error").GetComponent <ErrorSound>().playError();
            }

            else
            {
                Vector3 destination = atomicScript.getNeutronPosition(n + 1);
                lerpParticle(collision.gameObject, destination);
                atomicScript.addNeutron();
                collision.gameObject.SetActive(false);
                collision.gameObject.GetComponent <StartingPosition>().ResetToSpawn();
                collision.gameObject.SetActive(true);
                GameObject.Find("Popping").GetComponent <PoppingSound>().playPop();
            }
        }
        if (collision.gameObject.name.Contains("proton"))
        {
            int n = atomicScript.getAtomicNumber();

            // If proton total is already max (10)
            if (n == 10)
            {
                GameObject.Find("Error").GetComponent <ErrorSound>().playError();
            }

            else
            {
                Vector3 destination = atomicScript.getProtonPosition(n + 1);
                lerpParticle(collision.gameObject, destination);
                atomicScript.addProton();
                collision.gameObject.SetActive(false);
                collision.gameObject.GetComponent <StartingPosition>().ResetToSpawn();
                collision.gameObject.SetActive(true);
                GameObject.Find("Popping").GetComponent <PoppingSound>().playPop();
            }
        }
    }