Ejemplo n.º 1
0
    private void colliderHelper(Collider2D[] collider, bool allColliders)
    {
        bool leftCol  = false;
        bool rightCol = false;

        foreach (var collide in collider)
        {
            if (collide.gameObject.tag == "Push")
            {
                pushBlock pushScript = collide.gameObject.GetComponent <pushBlock>();
                leftCol  = pushScript.leftCol;
                rightCol = pushScript.rightCol;
            }
            if (collide.gameObject.GetComponent <Collideable>() && allColliders == true)
            {
                if (!masterScript.grounded && !masterScript.grounded2)
                {
                    col = true;
                    distanceToCollision = GetComponent <BoxCollider2D>().Distance(collide).distance;
                }
                else if (collide.gameObject.tag != "Push" || ((collide.gameObject.tag == "Push" && !Input.GetButton("Push"))) || (((collide.gameObject.tag == "Push" && Input.GetButton("Push"))) && ((leftCol && moveDirection == -1) || (rightCol && moveDirection == 1))))
                {
                    col = true;
                    distanceToCollision = GetComponent <BoxCollider2D>().Distance(collide).distance;
                }
            }
            else if (collide.gameObject.tag == "MoveBox" && allColliders == false)
            {
                float otherMovingSpeed = collide.gameObject.GetComponent <HorizontalBox>().speed;
                col = true;
                if (otherMovingSpeed < 0)
                {
                    distanceToCollision = GetComponent <BoxCollider2D>().Distance(collide).distance + .04f;
                }
                else if (otherMovingSpeed > 0)
                {
                    distanceToCollision = GetComponent <BoxCollider2D>().Distance(collide).distance - .04f;
                }
                else
                {
                    distanceToCollision = GetComponent <BoxCollider2D>().Distance(collide).distance;
                }
            }
        }
    }
Ejemplo n.º 2
0
    private void collidePush(Collider2D[] collider, bool onLeft)
    {
        bool leftCol  = false;
        bool rightCol = false;

        foreach (var collide in collider)
        {
            if (collide.gameObject.tag == "Push")
            {
                pushBlock pushScript = collide.gameObject.GetComponent <pushBlock>();
                leftCol  = pushScript.leftCol;
                rightCol = pushScript.rightCol;
            }
            if (collide.gameObject.tag == "Push" && Input.GetButton("Push"))
            {
                if (!grabState)
                {
                    grabState = true;
                    charAnim.SetTrigger("grabStart");
                }
                //Debug.Log(grabState);
                //charAnim.SetBool("grabbing", true);
                if ((!leftCol && moveDirection == -1) || (!rightCol && moveDirection == 1))
                {
                    if (onLeft)
                    {
                        pushLeft = true;
                    }
                    else
                    {
                        pushRight = true;
                    }
                    touchingMoving = true;
                    if (moveDirection == 1)
                    {
                        if (masterScript.grounded || masterScript.grounded2)
                        {
                            movingPush = speed * 1 / 2;
                            collide.gameObject.GetComponent <pushBlock>().movingPush = movingPush;
                        }
                    }
                    else if (moveDirection == -1)
                    {
                        if (masterScript.grounded || masterScript.grounded2)
                        {
                            movingPush = -speed * 1 / 2;
                            collide.gameObject.GetComponent <pushBlock>().movingPush = movingPush;
                        }
                    }
                }
            }
            else if (collide.gameObject.GetComponent <Collideable>())
            {
                if (onLeft)
                {
                    nonPushLeft = true;
                }
                else
                {
                    nonPushRight = true;
                }
            }
        }

        charAnim.SetBool("pushRight", pushRight);
        charAnim.SetBool("pushLeft", pushLeft);
        //charAnim.SetBool("grabbing", Input.GetButton("Push"));
    }