Maybe you can check the y component of the velocity and if it's positive (upwards) set it to 0? If it's negative (downwards) just keep it.
PS. I think you should get a variable referencing the rigidbody component to minimize the GetComponent calls.
Vector3 v = rb.velocity; //get the velocity
v.y = v.y > 0 ? 0 : v.y; //set to 0 if positive
rb.velocity = v; //apply the velocity
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…