Esempio n. 1
0
    void OnTriggerEnter2D(Collider2D col)
    {
        // Enemy
        if (col.gameObject.layer == LayerMask.NameToLayer("Enemy"))
        {
            col.GetComponent <Enemy> ().Hit();

            rb.isKinematic = true;

            this.gameObject.SetActive(false);
        }

        if (((1 << col.gameObject.layer) & groundLayer) != 0)
        {
            rb.Sleep();
            rb.gameObject.SetActive(false);
        }

        // Obstacle
        if (((1 << col.gameObject.layer) & obstacleLayer) != 0)
        {
            // Don't hit fire
            if (!col.gameObject.CompareTag("Fire"))
            {
                rb.Sleep();
                rb.AddForce(new Vector2(-1f, 1f) * obstacleForce);
            }
        }

        if (col.gameObject.CompareTag("Egg"))
        {
            Egg egg = col.GetComponent <Egg> ();

            if (!egg.isCracked)
            {
                rb.Sleep();
                rb.AddForce(new Vector2(-1.2f, 1.2f) * obstacleForce);
            }

            egg.Hit();
        }
    }