Пример #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        PlayerBody pb = collision.gameObject.GetComponent <PlayerBody>();

        if (collision.transform.CompareTag("Player") && player != (int)pb.WhichPlayer && !pb.Lying)
        {
            pb.Hitted(damage);
            pb.ShowEmoji(PlayerBody.Emojis.Hitted, 0.3f);

            /*int temp = (int)Random.Range(6, 9);
             * collision.gameObject.GetComponent<PlayerBody>().Loss_Garbage(temp);
             */
            Vector2 vector2 = new Vector2(-transform.up.x, -transform.up.y);
            for (int i = 0; i < damage; i++)
            {
                Drop(vector2);
            }

            SoundPlay("sfx/ShootHit");
            Rigidbody2D.velocity = Vector3.zero;
            PoolRecycle();
        }

        if (collision.transform.CompareTag("Wall"))
        {
            Vector2 vector2 = Vector2.zero;
            switch (collision.name)
            {
            case "Wall_left":
                vector2.x = 1;
                break;

            case "Wall_right":
                vector2.x = -1;
                break;

            case "Wall_up":
                vector2.y = -1;
                break;

            case "Wall_down":
                vector2.y = 1;
                break;

            default: break;
            }

            for (int i = 0; i < damage; i++)
            {
                Drop(vector2);
            }
            Rigidbody2D.velocity = Vector3.zero;
            PoolRecycle();
        }
    }
Пример #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        PlayerBody pb = collision.gameObject.GetComponent <PlayerBody>();

        if (pb != null)
        {
            if (pb.WhichPlayer != WhichPlayer)
            {
                if (collision.CompareTag("Player") && !pb.Lying)
                {
                    Vector3 pos3 = collision.transform.position - transform.position;
                    Vector2 pos  = new Vector2(pos3.x, pos3.y);
                    Vector2 spe  = pb.rb.velocity - rb.velocity;
                    float   temp = spe.magnitude;

                    if (temp > (pb.move.max_speed + move.max_speed) * ContactX && Vector2.Dot(pos, spe) < 0)
                    {
//                        Debug.Log(temp + "||" + (pb.move.max_speed + move.max_speed) * ContactX);
                        pb.Hitted(ContactDamage);
                        pb.ShowEmoji(Emojis.Hitted, 0.3f);

                        if (HardCollisionTick > HardCollisionCD)
                        {
                            HardCollisionTick = 0;
                            SoundPlay("sfx/HardCollision");
                        }
                    }
                    else
                    {
                        if (CollisionTick > CollisionCD)
                        {
                            SoundPlay("sfx/Collision");
                        }
                    }
                }
            }
        }
    }