void OnCollisionEnter2D(Collision2D coll)
    {
        //print (coll.gameObject.name);
        if (isExtended && !isRetracting && !isPullingPlayer)
        {
            if (coll.collider.CompareTag("Hook") && canPullPlayer)
            {
                player.layer    = 20;
                isPullingPlayer = true;
            }
            else if (coll.collider.CompareTag("PullBlock"))
            {
                isRetracting = true;
                float     xDist = coll.transform.position.x - player.transform.position.x;             //if xDist is negative, player is right, else player is left
                float     yDist = coll.transform.position.y - player.transform.position.y;             //if xDist is negative, player is up, else player is down
                PullBlock block = coll.gameObject.GetComponent <PullBlock> ();

                if (Mathf.Abs(xDist) > Mathf.Abs(yDist))
                {
                    //horizontal movement
                    if (xDist < 0)
                    {
                        //moveRight
                        block.Pull(PullBlock.Directions.RIGHT);
                    }
                    else
                    {
                        //moveLeft
                        block.Pull(PullBlock.Directions.LEFT);
                    }
                }
                else
                {
                    //vertical movement
                    if (yDist < 0)
                    {
                        //moveUp
                        block.Pull(PullBlock.Directions.UP);
                    }
                    else
                    {
                        //moveDown
                        block.Pull(PullBlock.Directions.DOWN);
                    }
                }
            }
            else if (coll.collider.CompareTag("Item") && canGrabItems)
            {
                isRetracting = true;
                hasItem      = true;
                coll.collider.transform.SetParent(transform);
            }
            else
            {
                isRetracting = true;
            }
        }
    }
Exemple #2
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (enu_status != Status.Shot)
        {
            return;
        }

        flg_hit     = true;
        pos_contact = col.contacts [0].point;

        //最初の無音部分をキングクリムゾンします
        Catcher_SE.time = 0.2f;
        Catcher_SE.Play();


        switch (col.gameObject.tag)
        {
        case "ApproachBlock":
            enu_status = Status.HitApproachBlock;
            break;

        case "PullBlock":
            scr_pullBlock = col.gameObject.GetComponent <PullBlock> ();
            scr_pullBlock.AttachParent(gameObject);
            enu_status = Status.HitPullBlock;
            break;

        case "StayBlock":
            enu_status = Status.HitStayBlock;
            break;

        case "NomalBlock":
            enu_status = Status.HitNomalBlock;
            break;

        case "MoveBar":
            //enu_status = Status.HitNomalBlock;
            break;
        }
    }