How to calculate distance in unity

I make a 2D unity game like Flappy Bird but in game gameObjects(bird and main camera) are not move only obstacles are move so how i can calculate distance.

currentPosition = begningPosition-bird.transform.position.x; distance = Mathf.RoundToInt (currentPosition); GameController.instance.SetDistancce (distance);

I made a 2D unity game like Flappy Bird but gameObjects (bird and main camera) are not moving but the obstacles are, so how can I calculate the distance?

currentPosition = beginningPosition-bird.transform.position.x; 
distance = Mathf.RoundToInt (currentPosition); 
GameController.instance.SetDistancce (distance);

Horrible grammar. You can’t expect anyone to understand what are you saying. And now that I have fixed that for you, I don’t know what distance are you trying to calculate, and I don’t know what is the GameController. Only thing I can say is that you are setting the distance to float x in the position of “beginningPosition-bird”. This is not correct. Transform.position is the position of the object in relation to the world. Distance must be from point A to point B. Use Distance(Vector2 a, Vector2 b).