示例#1
0
    private IEnumerator FreezePower()
    {
        IceBlockPhysics blockPhysics = iceBlock.GetComponent <IceBlockPhysics>();

        blockPhysics.GetRigidbody().constraints = RigidbodyConstraints2D.FreezeAll;
        blockPhysics.gameObject.GetComponent <SpriteRenderer>().color = color[4];
        GameUI.Instance.UsedPower(true);
        yield return(new WaitForEndOfFrame());
    }
示例#2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        IceBlockPhysics block = collision.GetComponent <IceBlockPhysics>();

        if (block != null && block.block == Block.fruitBlock)
        {
            block.DestroyByFalling();
        }
    }
示例#3
0
    private IEnumerator MovePower()
    {
        colide = false;
        IceBlockPhysics blockPhysics = iceBlock.GetComponent <IceBlockPhysics>();

        rbType = blockPhysics.RigidbodyGetType();
        blockPhysics.RigidbodyChange(RigidbodyType2D.Static);

        GameObject cloneOfTargetedObject = Instantiate(blockPhysics.gameObject);

        listOfColor.Add(blockPhysics.gameObject.GetComponent <SpriteRenderer>().color);
        blockPhysics.gameObject.GetComponent <SpriteRenderer>().color = color[1];
        //GetCollider
        var collider2d = cloneOfTargetedObject.GetComponent <Collider2D>();

        collider2d.isTrigger = true;
        BoxColliderScale.ScaleCollider(collider2d, true);
        SpriteRenderer spriteClone = cloneOfTargetedObject.GetComponent <SpriteRenderer>();

        spriteClone.sortingOrder = 15;

        while (true)
        {
            if (playerController.buttonUp)
            {
                uncheckPower = false;
                if (!colide)
                {
                    blockPhysics.transform.position = cloneOfTargetedObject.transform.position;
                    GameUI.Instance.UsedPower(true);
                }
                else
                {
                    GameUI.Instance.UsedPower(false);
                }
                Destroy(cloneOfTargetedObject.gameObject);
                blockPhysics.gameObject.GetComponent <SpriteRenderer>().color = listOfColor[0];
                blockPhysics.RigidbodyChange(rbType);
                listOfColor.Clear();
                uncheckPower = true;
                break;
            }

            CheckColision(spriteClone);
            Vector2 position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            cloneOfTargetedObject.transform.position = position;
            yield return(new WaitForEndOfFrame());
        }
    }
示例#4
0
    /*
     * private void OnCollisionStay2D(Collision2D collision) {
     *
     *  Debug.LogWarning(collision.gameObject.name);
     *
     *  foreach (ContactPoint2D contact in collision.contacts) {
     *      print(contact.collider.name + " hit " + contact.otherCollider.name);
     *      Debug.DrawRay(contact.point, contact.normal, Color.white);
     *  }
     * }*/
    /*
     * private void OnCollisionExit2D(Collision2D collision) {
     *  Debug.LogError(collision.gameObject.name + "EXIT");
     *
     *  velocityIgnore = Vector2.zero; //rb2D.velocity;
     *
     * }*/

    private void OnCollisionEnter2D(Collision2D collision)
    {
        float impactStrenghtHeight;
        float impactStrenghtWidth;

        bool rotation = CalculateRotation();

        if (rotation)
        {
            // Horizontal
            impactStrenghtHeight = (velocity.y - velocityIgnore.y) + strenghtHight;
            impactStrenghtWidth  = (velocity.x - velocityIgnore.x) + strenghtWidth;
        }
        else
        {
            //Vertical 90 degresse
            impactStrenghtHeight = velocity.y + strenghtWidth;
            impactStrenghtWidth  = velocity.x + strenghtHight;
        }

        CheckDestroy(impactStrenghtHeight, impactStrenghtWidth);


        if (block == Block.stoneBlock && (impactStrenghtHeight < 0 || impactStrenghtWidth < 0))
        {
            IceBlockPhysics blocks = collision.gameObject.GetComponent <IceBlockPhysics>();
            if (blocks != null && blocks.block != Block.stoneBlock && blocks.canBeDestroyed)
            {
                float strenghtH = blocks.strenghtHight;
                float strenghtW = blocks.strenghtWidth;

                if (rotation && (strenghtH < strenghtHight || strenghtW < strenghtWidth))
                {
                    blocks.DestroyByFalling();
                }
                else if (!rotation && (strenghtH < strenghtWidth || strenghtW < strenghtHight))
                {
                    blocks.DestroyByFalling();
                }
                else
                {
                    Vector2 vel = velocity - velocityIgnore;
                    blocks.CheckColision(vel);
                }
            }
        }
    }