Ejemplo n.º 1
0
    private void DetectObjectCollision()
    {
        var collisions = Physics.OverlapSphere(transform.position, 1.5f, grabbiesLayerMask);

        DebugExtensions.DebugWireSphere(transform.position, Color.black, 1.5f, 2f);

        if (collisions.Length == 0)
        {
            return;
        }

        var mergeableObject = collisions[0].GetComponentInParent <MergeableObject>();

        if (currentMergeableObject == null)
        {
            currentMergeableObject = mergeableObject;
            mergeableObject.transform.SetParent(grabbyPoint);
            mergeableObject.transform.localPosition = Vector3.zero;
            mergeableObject.transform.localRotation = Quaternion.identity;
            mergeableObject.transform.localScale    = Vector3.one;
            collisions[0].enabled = false;
            mergeableObject.GetComponent <FakeGravity>().enabled = false;

            AudioManager.Instance.PlayCombineSuccess();
            //Close hands
        }
        else
        {
            if (currentMergeableObject.UpgradeObjectByAddition(mergeableObject.VectorMaterial))
            {
                AudioManager.Instance.PlayCombineSuccess();
                Destroy(mergeableObject.gameObject);
            }
            else
            {
                AudioManager.Instance.PlayCombineFail();
            }
        }
    }