- Home /
Orientation Problem
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.
Answer by lamp · Dec 04, 2013 at 09:04 AM
Ok so the first issue i realised it was a foolish mistake on my part. As i had orientation called from FixedUpdate it was repositioning my objects constantly to the same location. Within that i Coroutine disabling the hit until the scene had loaded. So because it was always being called it never had a chance to enable the raycast
Your answer
Follow this Question
Related Questions
How to check iOS Device Generation ? 0 Answers
How to allow automatic screen rotation in iOS? 2 Answers
How to test Screen Orientation? 3 Answers
Android Game Orientation cannot be fixed to potrait 0 Answers