public void ActivateAura(bool activate)
    {
        child.gameObject.SetActive(activate);
        auraIsActive = activate;
        if (!activate)
        {
            foreach (RaycastHit2D box in boxes)
            {
                MovebleItems moveble = box.transform.gameObject.GetComponent <MovebleItems>();
                moveble.resetValues(false);
            }

            boxes = new RaycastHit2D[0];
        }
    }
Exemple #2
0
    private void Update()
    {
        RaycastHit2D raycastHit = Physics2D.BoxCast(buttonCollider.bounds.center, buttonCollider.bounds.size, 0f, Vector2.down * -1, extraHeightText, ableToClick);
        Color        rayColor;

        bool isHeavy = false;

        if (raycastHit.collider != null)
        {
            rayColor = Color.green;
        }
        else
        {
            rayColor = Color.red;
        }

        bool result = raycastHit.collider != null;

        if (result && !isNormal)
        {
            MovebleItems mI = raycastHit.transform.gameObject.GetComponent <MovebleItems>();
            if (mI != null)
            {
                isHeavy = mI.GetIsHeavy();
            }
        }

        if (isNormal)
        {
            Activate(result != previosResult);
        }
        else
        {
            Activate(isHeavy != previosIsHeavy);
        }



        previosIsHeavy = isHeavy;
        previosResult  = result;

        Debug.DrawRay(buttonCollider.bounds.center + new Vector3(buttonCollider.bounds.extents.x, 0), Vector2.down * -1 * (buttonCollider.bounds.extents.y + extraHeightText), rayColor);
        Debug.DrawRay(buttonCollider.bounds.center - new Vector3(buttonCollider.bounds.extents.x, 0), Vector2.down * -1 * (buttonCollider.bounds.extents.y + extraHeightText), rayColor);
        Debug.DrawRay(buttonCollider.bounds.center + new Vector3(-buttonCollider.bounds.extents.x, buttonCollider.bounds.extents.y + extraHeightText), Vector2.right * buttonCollider.bounds.extents.x * 2, rayColor);
    }
    // Update is called once per frame

    private void FixedUpdate()
    {
        if (auraIsActive)
        {
            RaycastHit2D[] newBoxes = Physics2D.CircleCastAll(transform.position, affectArea, Vector3.left, 0, layer2BeAffected);

            if (newBoxes.Length > 0)
            {
                foreach (RaycastHit2D box in newBoxes)
                {
                    MovebleItems moveble = box.transform.gameObject.GetComponent <MovebleItems>();
                    if (!moveble.IsActivate)
                    {
                        moveble.resetValues(true);
                    }
                }
                boxes = newBoxes;
            }
        }
    }