Detect Device Orientation through Script

As the title suggest, I want to detect device orientation change at run time.
So that I have to write script for that.
Basically I am planning to develop 2d game that work on both orientation.

But how to detect that is basic question? Because I am pretty new to this engine.

I have other questions in mind.
On android devices, I want to run my game in landscape mode in tablet and in portrait mode in mobile (Small Devices).

On iOS devices, I want to run my game in landscape mode in iPad and in portrait mode in iPhone.

How to perform this through script?

You could change the layout based on Input.deviceOrientation. Something like

void Update() {
	if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft) {
		UseLandscapeLeftLayout();
	}
	else if (Input.deviceOrientation == DeviceOrientation.Portrait) {
		UsePortraitLayout();
	}
}

In those UseLayout-functions you could for example change the position of GUI-elements or change what will be drawn OnGUI().