예제 #1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (leftCollision)
        {
            ContactPoint2D[] contact = new ContactPoint2D[1];
            collision.GetContacts(contact);

            moveSpeed *= collisionSpeedCoefficient;
            float oldMoveAngle = moveAngle - 180f;
            moveAngle = ReflectAngle(moveAngle, contact[0].normal);

            float sparkDuration = 0.3f + ((moveSpeed / initialSpeed) * 0.4f);

            for (int i = 0; i < 2; i++)
            {
                Spark.GetFromPool(sparkPrefab).Initialize(contact[0].point, oldMoveAngle + Random.Range(-5f, 5f),
                                                          sparkDuration,
                                                          (moveSpeed / initialSpeed) * Random.Range(0.5f, 2f), 0.2f, Random.Range(1f, 2f));
            }

            for (int i = 0; i < 2; i++)
            {
                Spark.GetFromPool(sparkPrefab).Initialize(contact[0].point, moveAngle + Random.Range(-5f, 5f),
                                                          sparkDuration,
                                                          (moveSpeed / initialSpeed) * Random.Range(0.5f, 2f), 0.2f, Random.Range(1f, 2f));
            }
        }

        leftCollision = false;
    }