Ejemplo n.º 1
0
    // ********************************************** //
    // Collision Events

    // Collision when first touched
    void OnCollisionEnter2D(Collision2D c)
    {
        if (c.gameObject.tag == "Speed Boost" || c.gameObject.tag == "Platforms" || c.gameObject.tag == "Collidables")
        {
            m_OnGround = true;

            if (c.gameObject.tag == "Collidables")
            {
                Vector3 Distance = transform.position - c.transform.position;
                if (Distance.y < 0.45f)
                {
                    m_VelocityX = 0;
                }
            }
            if (c.gameObject.tag == "Speed Boost")
            {
                m_Rb2D.AddForce(new Vector3(1000, 0, 0));
            }
        }
        else if (c.gameObject.tag == "Jumping Pad")
        {
            m_OnGround = false;
            m_Rb2D.AddForce(new Vector3(0, 1500, 0));
        }

        //if (c.gameObject.tag == "Downwards")
        //{
        //    m_VelocityX = 0;
        //}

        if (c.gameObject.tag == "Finish Line")
        {
            m_VelocityX  = 0;
            m_IsFinished = true;
            //pass in player to the standings list
            m_ScoreInfo.Set(this.name, m_TimeTaken);
            ScoreManager.Instance.AddToList(m_ScoreInfo);

            Debug.Log("Time Taken Player " + name + " : " + m_TimeTaken + "s");
            Debug.Log("timeSinceLevelLoad: " + m_TimeTaken);
        }

        if (c.gameObject.tag == "Boundary")
        {
            //m_VelocityX = 0;
            //Get All Platforms in level
            GameObject spawnObject = FindClosest("Platforms");
            this.transform.position = new Vector3(spawnObject.transform.position.x - 10, spawnObject.transform.position.y + 5, spawnObject.transform.position.z);
        }
    }