Creating a max height for character

Im both teaching myself c# and how to use unity so im a massive noob. Im trying to create a flying character which can fly to a max height then stop, this is what i have…

if(rigidbody.position.y == 100)
		{
			rigidbody.velocity =  Vector3.zero;
			rigidbody.angularVelocity = Vector3.zero;
			print("max height reached");
				
		}

My character does not stop and max height isnt printed so i know it is not registering the height of rigidbody.
I know its simple but i only have a simple understanding of c#, any help would be great.

You need to change line 1 to:

if (rigidbody.position.y >= 100.0)

There are a couple of issues with direct equality. First it is rare for calculated floating point numbers to be exactly some value. Second, Unity operates in discrete steps, so it will almost always skip over exact values.

Thanks, worked perfectly.