public void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Slope")) { Slope s = collision.gameObject.GetComponent <Slope>(); if (!sliding || s.GetHeight() > slopeHeight || slopeDir != (collision.gameObject.GetComponent <Slope>().facingRight ? 1 : -1)) { slopeHeight = collision.gameObject.GetComponent <Slope>().GetHeight(); slopeDir = collision.gameObject.GetComponent <Slope>().facingRight ? 1 : -1; } } }