Hello all.
Have been struggling with problems in regards to orientation. In its basic form i have a scene with a cube and box collider. I have a raycast which will tell me weather i have hit the cube object or not and Im using the code below to control the device orientation. Works grand in the player however on device it will only detect touch when the device is either face down or face up. Im assuming that this is because Input.deviceOrientation can return faacedown and faceup which throws off the if statements but i cant for the life of me figure out how to get around it so that it will detect touch when device is faceing side on.
If any of you wonderful people have a solution or a better alternative im all ears.
void orientation(){
if(Input.deviceOrientation == DeviceOrientation.LandscapeLeft){
Screen.orientation = ScreenOrientation.LandscapeLeft;
currentOrientation = ScreenOrientation.LandscapeLeft;
landscape = true;
reposition();
}
else if(Input.deviceOrientation == DeviceOrientation.LandscapeRight){
Screen.orientation = ScreenOrientation.LandscapeRight;
currentOrientation = ScreenOrientation.LandscapeRight;
landscape = true;
reposition();
}
else if(Input.deviceOrientation == DeviceOrientation.Portrait){
Screen.orientation = ScreenOrientation.Portrait;
currentOrientation = ScreenOrientation.Portrait;
landscape = false;
reposition();
}
else if(Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown){
Screen.orientation = ScreenOrientation.PortraitUpsideDown;
currentOrientation = ScreenOrientation.PortraitUpsideDown;
landscape = false;
reposition();
}
}
Additionally
Additionally though iv now encountered a second issue. I am using a similar script to read the last known device orientation (either landscape or portrait) and then set the start of each scene accordingly. This works fine for two scenes but not the third.
Essentially when i load the scene, it gets the last known orientation and calls the above script to sett the screen orientation and reposition all of the gameobjects. It repositions the GameObjects correctly so i know its reading the last orientation, however it does not set the ScreenOrientation. I can find any similar examples other than for older unity versions or windows phone. Developing in unity 4.1 for iPad. Same issue repeats on android however.