Пример #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        //explode if a player comes within range
        if (collision.gameObject.CompareTag("Player") && !exploded)
        {
            exploded = true;
            RpcSendExploded(exploded);
            print("sending exploded status to server");
            startTime = Time.time;

            //knocks back all rigidbodies and applies a 0.5 second stun to players within the blast radius of 20 units
            Collider2D[] inRange = Physics2D.OverlapCircleAll(transform.position, 20);
            foreach (Collider2D cd in inRange)
            {
                GameObject  other = cd.gameObject;
                Rigidbody2D rb    = other.GetComponent <Rigidbody2D>();
                if (rb != null)
                {
                    Vector2 direction = (other.transform.position - transform.position).normalized;
                    rb.AddForce(new Vector2(direction.x, direction.y + 0.2f) * blastForce);
                    Platformer2DUserControl robot = other.GetComponent <Platformer2DUserControl>();
                    if (robot != null)
                    {
                        robot.applyStun(0.5f);
                    }
                    ;
                }
            }
        }
    }
    private void explode()
    {
        //this bomb explodes into 8 fragments, which fly in all directions
        for (float i = 0; i < 360; i += 360f / 8f)
        {
            GameObject newfragment = Instantiate(fragment, new Vector2(transform.position.x + 2 * Mathf.Sin((i * Mathf.PI) / 180f), transform.position.y + 2 * Mathf.Cos((i * Mathf.PI) / 180f)), Quaternion.identity);
            newfragment.GetComponent <Rigidbody2D>().velocity = new Vector2(50 * Mathf.Sin((i * Mathf.PI) / 180f), 50 * Mathf.Cos((i * Mathf.PI) / 180f));
            NetworkServer.Spawn(newfragment);
        }

        //interrupts movement of players within 5 units radius and applies a 0.4 second stun to them
        Collider2D[] inRange = Physics2D.OverlapCircleAll(transform.position, 5);
        foreach (Collider2D cd in inRange)
        {
            GameObject other = cd.gameObject;
            Platformer2DUserControl robot = other.GetComponent <Platformer2DUserControl>();
            if (robot != null)
            {
                robot.applyStun(0.4f);
                other.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
            }
        }
        NetworkServer.Destroy(gameObject);
        Destroy(gameObject);
    }
 private void explode()
 {
     //interrupts the movement of players within a 5 unit radius, and applies a 0.4 second stun to them.
     Collider2D[] inRange = Physics2D.OverlapCircleAll(transform.position, 5);
     foreach (Collider2D cd in inRange)
     {
         GameObject other = cd.gameObject;
         Platformer2DUserControl robot = other.GetComponent <Platformer2DUserControl>();
         if (robot != null)
         {
             robot.applyStun(0.4f);
             other.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
         }
     }
 }
 private void OnCollisionEnter2D(Collision2D collision)
 {
     //when rocket hits something, it explodes,
     //interrupting the movement of players within a 5 unit radius and stunning them for 0.4 seconds
     Collider2D[] inRange = Physics2D.OverlapCircleAll(transform.position, 5);
     foreach (Collider2D cd in inRange)
     {
         GameObject other = cd.gameObject;
         Platformer2DUserControl robot = other.GetComponent <Platformer2DUserControl>();
         if (robot != null)
         {
             robot.applyStun(0.4f);
             other.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
         }
     }
     NetworkServer.Destroy(gameObject);
     Destroy(gameObject);
 }