Exemplo n.º 1
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == Tags.BALL)
     {
         isTriggered = true;
         onSwitchEvent.Call();
     }
 }
Exemplo n.º 2
0
    void OnTriggerEnter2D(Collider2D trigger)
    {
        if (trigger.gameObject.tag == Tags.BALL && !isTeleportatingNow)
        {
            onSwitchPortalCondition(false);
            onTeleportate.Call();

            TurnOnExitsFromPortal(this);

            foreach (GameObject bindedPortal in bindedPortals)
            {
                float angle = bindedPortal.transform.eulerAngles.z - this.gameObject.transform.eulerAngles.z + 180;

                Vector2 newPosition = bindedPortal.transform.position;

                Vector2 speed = trigger.gameObject.GetComponent <Rigidbody2D> ().velocity;
                speed = GetNewVectorForObject(angle, speed);

                GameObject createdBall = Instantiate(trigger.gameObject, newPosition, Quaternion.identity) as GameObject;

                createdBall.GetComponent <CircleCollider2D>().enabled   = true;
                createdBall.GetComponent <BallController>().enabled     = true;
                createdBall.GetComponent <BallAppearance>().enabled     = true;
                createdBall.GetComponentInChildren <Animator>().enabled = true;
                createdBall.GetComponent <BallAppearance>().SetFlyingAnimation();
                createdBall.GetComponent <Rigidbody2D> ().isKinematic = false;

                createdBall.GetComponent <Rigidbody2D> ().velocity = speed;
                Destroy(trigger.gameObject);
            }
        }
    }
Exemplo n.º 3
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == Tags.BALL)
        {
            float jumperAngle = this.gameObject.transform.eulerAngles.z;

            collision.gameObject.GetComponent <Rigidbody2D>()
            .AddForce(GetForceVector(jumperAngle, chosenJumperPower));
            onBallCollide.Call();
        }
    }
Exemplo n.º 4
0
    private IEnumerator OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == Tags.BALL &&
            !collision.gameObject.GetComponent <BallController>().IsSafeColliding)
        {
            collision.gameObject.GetComponent <BallController>().DestroyBall();
            GameObject newParticles = Instantiate(particles, collision.transform.position, Quaternion.identity) as GameObject;

            onBallCollide.Call();

            yield return(new WaitForSeconds(PARTICLES_LIFE_TIME));

            Destroy(newParticles);
        }
    }
    /// <summary>
    /// Raises the collision enter2 d event.
    /// </summary>
    /// <param name="collision">Collision.</param>
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == Tags.BALL)
        {
            Rigidbody2D rBody = collision.gameObject.GetComponent <Rigidbody2D>();
            rBody.constraints = RigidbodyConstraints2D.FreezeAll;

            collision.gameObject.GetComponent <BallController>().IsSafeColliding = true;
            collision.gameObject.transform.SetParent(this.gameObject.transform);

            onBallCollide.Call();
            levelService.OnBallStick.Call();
            collision.gameObject.GetComponent <BallController>().OnGrounded.Call();
        }
    }
    /// <summary>
    /// Raises the collision stay2 d event.
    /// </summary>
    /// <param name="collision">Collision.</param>
    void OnTriggerStay2D(Collider2D collision)
    {
        if (inputService.IsInputDown())
        {
            RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

            if (hit.collider != null &&
                fireButton.Equals(hit.collider.gameObject))
            {
                isCharging = true;
                onBallCharging.Call();
            }
        }

        if (inputService.IsInputUp())
        {
            RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

            if (hit.collider != null &&
                fireButton.Equals(hit.collider.gameObject) ||
                isCharging)
            {
                platformPowerCurrent *= inputService.GetTimeOfClick() > delaySecondsMaximum
                                        ? delaySecondsMaximum : inputService.GetTimeOfClick();

                collision.gameObject.transform.parent = null;
                Rigidbody2D rBody = collision.gameObject.GetComponent <Rigidbody2D>();
                rBody.constraints = RigidbodyConstraints2D.None;
                rBody.AddForce(GetForceVector(this.gameObject.transform.eulerAngles.z, platformPowerCurrent));

                platformPowerCurrent = PLATFORM_POWER_BASE * platformPowerMultiplier;
                isCharging           = false;

                collision.gameObject.GetComponent <BallController>().IsSafeColliding = false;

                collision.gameObject.GetComponent <BallController>().OnReleased.Call();
                onBallRelease.Call();
                levelService.OnBallRelease.Call();
            }
        }
    }
Exemplo n.º 7
0
 void OnCollisionEnter2D()
 {
     onBallCollide.Call();
 }