Пример #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (otherTeleporter == null)
        {
            return;
        }
        if (collision.GetComponent <Rigidbody2D>())
        {
            if (SoundManager.instance != null)
            {
                SoundManager.instance.PlaySFX("SFX_Teleport");
            }

            Rigidbody2D collisionRb = collision.GetComponent <Rigidbody2D>();
            //if not on the check list (ie. is entering a tele)...
            if (!CheckList(collisionRb))
            {
                collision.transform.position = otherTeleporter.position;                            // Set position of teleporting object to other teleporter
                otherTeleportScript.AddRecentlyTeleported(collision.GetComponent <Rigidbody2D>());  // Add teleporting gameobject to other tele's list of teleported objects.
                if (particles != null)
                {
                    particles[0].Play();            // The "going" particle effect is the first child of the teleporter
                }
                else
                {
                    Debug.Log("Particles not found for " + name + ", rediscovering...");
                    particles = GetComponentsInChildren <ParticleSystem>();
                    particles[0].Play();
                }

                if (collision.GetComponent <Projectile>())
                {
                    collision.GetComponent <Projectile>().range += Vector2.Distance(otherTeleporter.position, transform.position);
                }
            }
            // The "arrival" particle effect is the second child of the teleporter
            else
            {
                particles[1].Play();
            }
        }
    }