Example #1
0
    private void OnTriggerEnter2D(Collider2D opponent)
    {
        if (opponent.gameObject.tag == "Block")
        {
            moveBlocked = true;
            GameObject  block  = opponent.gameObject;
            ToggleBlock shield = opponent.GetComponent <ToggleBlock>();
            shield.shieldDurability--;

            if (shield.shieldDurability <= 0)
            {
                StartCoroutine(KillShield(block));
            }
        }
        //Applies knockback to opponent
        if (opponent.gameObject.tag == "Player")
        {
            Rigidbody2D opposingHitbox = opponent.gameObject.GetComponent <Rigidbody2D>();
            Vector2     hitReaction;
            int         direction;

            //Determines direction of knockback
            if (facingRight == true)
            {
                direction = 1;
            }
            else
            {
                direction = -1;
            }

            hitReaction = new Vector2(120.0f * direction, 80.0f);
            opposingHitbox.AddForce(hitReaction * knockback);

            Movement move = opponent.gameObject.GetComponent <Movement>();

            if (move.stunCheck != null)
            {
                StopCoroutine(move.stunCheck);
            }

//            Transform shield = opponent.gameObject.transform.GetChild(2);
//            ToggleBlock shieldCheck = shield.GetComponent<ToggleBlock>();
//           Debug.Log(shieldCheck.shieldUp);

            //Activates hitstun coroutine from Movement script
            if (moveBlocked == false)
            {
                move.stunCheck = StartCoroutine(opponent.GetComponent <Movement>().GotHit());
            }

            if (moveBlocked == true)
            {
                moveBlocked = false;
            }
        }
    }
 void SelectBlock(ToggleBlock b)
 {
     b.Toggle();
     if (Blocks.Contains(b))
     {
         Blocks.Remove(b);
     }
     if (b.Active)
     {
         Blocks.Add(b);
         b.SetOrder(Blocks.Count);
         Debug.Log("Set order #" + Blocks.Count);
     }
 }