コード例 #1
0
    void OnCollisionEnter(Collision collisionInfo)
    {
        if (collisionInfo.gameObject != null && referenceScript != null)
        {
            if (collisionInfo.collider.tag.Contains("Metal"))
            {
                // Getting info on the metal.
                Metal M   = collisionInfo.gameObject.GetComponent <Metal>();
                float neq = M.GetNeq();
                float nm  = M.GetNm();

                float delta_na = Mathf.Min(nm - neq, _na);

                UpdateNa(delta_na);
                // triggering corroding updates
                M.UpdateNeq(delta_na);

                referenceScript.addMetal(M);

                if (_na == 0)
                {
                    visual.enabled = false;

                    // ------------- Insert animation here ----------------- //

                    Destroy(gameObject);
                }
            }
        }
    }
コード例 #2
0
    void OnCollisionStay(Collision collisionInfo)
    {
        foreach (ContactPoint contact in collisionInfo.contacts)
        {
            Debug.DrawRay(contact.point, contact.normal, Color.white);
        }


        if (collisionInfo.collider.tag.Contains("voxel"))
        {
            // Getting the info on the Metal
            Metal M   = collisionInfo.gameObject.GetComponent <Metal>();
            float neq = M.GetNeq();
            float nm  = M.GetNm();

            // computing the amount of acid that will be consumed
            float delta_na = Mathf.Min(nm - neq, _na);

            // updating the amount of acid of the projectile
            UpdateNa(delta_na);

            // triggering corroding updates
            M.UpdateNeq(delta_na);
            referenceScript.addMetal(M);

            // Destroys the Acid
            if (_na == 0)
            {
                visual.enabled = false;
                Destroy(gameObject);
            }
        }
    }