how to set orientation for each scene in unity3d - unity3d

I have 4 scenes in my game
I need to set scene 1 and scene 3 in landscape mode, scene 2 and scene 4 in portrait mode
how can I do this?
please help me out...
I'm searching for a long time but couldn't find out the answer

You can have a script that checks for the actual level and changes the orientation in according to the retrieved value.
As an example:
function Start(){
if (Application.LoadedLevel == 1)
Screen.orientation = ScreenOrientation.LandscapeLeft;
else if (Application.LoadedLevel == 2)
Screen.orientation = ScreenOrientation.Portrait;
//...
}
More info about usage and orientation values.

Since around Unity 5.3 there is a new API for getting the current scene.
This example forces the screen orientation on mobile devices to portrait on a scene called "GameView" and landscape otherwise.
using UnityEngine;
using UnityEngine.SceneManagement;
public class ScreenOrientationScript : MonoBehaviour {
void Start () {
if (Application.isMobilePlatform == true) {
if (SceneManager.GetActiveScene().name == "GameView") {
Screen.orientation = ScreenOrientation.Portrait;
} else {
Screen.orientation = ScreenOrientation.Landscape;
}
}
}
}
Sample iOS setting to allow orientations

Unity uses single/sole activity for ALL Levels/Scenes, which is com.unity3d.player.UnityPlayerActivity, as can be found in AndroidManifest.xml file.
So all you need do is to specify the orientation in the Player Setting Inspector (Default Orientation part):

Related

Coremotion and iPhone orientation by starting App

I am developing an App with Coremotion and Swift and only for landscape mode. I have the accelerometer (part of Coremotion) working. But when my iPhone orientation is Portrait, the accelerometer is active at the moment.
When I start the app in portrait mode, then it is not possible to stop the accelerometer. Because the app is designed for only landscape and then there is no possibility to test on portrait mode (Swift things de iPhone is always in landscape mode).
Can someone tell me how to make accelerometer only active by starting the app, when the iPhone is only in landscape mode?
Here some code:
viewdDidLoad:
if(motionManager.isDeviceMotionAvailable){
motionManager.startDeviceMotionUpdates();
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
}
motionManager.startAccelerometerUpdates()
func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval):
if let rot = motionManager.deviceMotion?.attitude{
cameraNode.eulerAngles = SCNVector3Make(Float(rot.roll +
M_PI/2), -Float(rot.yaw), -Float(rot.pitch))
Edit: Making sure this has been done. See below image.
Try :
viewDidAppear() {
super.viewDidAppear()
if UIDevice.current.orientation == UIDeviceOrientation.landscapeLeft || UIDevice.current.orientation == UIDeviceOrientation.landscapeRight {
if(motionManager.isDeviceMotionAvailable){
motionManager.startDeviceMotionUpdates();
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
}
motionManager.startAccelerometerUpdates()
} // else you could do a notification on orientation left/right
}

Virtual Joystick moving sprite while changing animations

I'm working on a project where I'll have a virtual joystick on the screen which moves a character around the board. I found a few good examples and the one I'm using currently is located # https://github.com/Ishawn-Gullapalli/SpritekitJoystick/tree/master/SpritekitJoystick
While the player is moved around just like I want, I'm unable to figure out how by using this method I can change the player animation based on the direction he's going. I'm able to determine direction but my usual methods of invoking a SKAction doesn't animate the player, it just moves him to the new location while pausing the idle animation. I'm moving my player in the update statement like below and am looking for tips on how to change animations appropriately.
I'm including my update statement below. I've also tried to pass in a CGPoint value with the same effect. Thanks in advance for looking.
override func update(_ currentTime: TimeInterval) {
if joystick.joyStickTouched == true {
mainHero.position.x += joystick.moveRight(speed: movementSpeed)
// Example of me trying to animate my player
if joystick.moveRight(speed: movementSpeed) > 0 {
walkRight()
}
mainHero.position.x -= joystick.moveLeft(speed: movementSpeed)
mainHero.position.y += joystick.moveUp(speed: movementSpeed)
mainHero.position.y -= joystick.moveDown(speed: movementSpeed)
joystick.update(currentTime)
}
}
func walkRight() {
mainHero.isPaused = false
let idleAnimation = SKAction(named: "MainWalkRight")!
let rightGroup = SKAction.group([idleAnimation])
mainHero.run(rightGroup, withKey: "Right")
}

Why won't the scene pause?

I am trying to pause my scene when my SCNPyramid reaches a certain coordinate to setup my tutorial for game. However, the scene never pauses and I am not sure why.
if (leftSpike5.position.x == 0.4) {
self.isPaused = true
}

Unity check if scene == gamescene?

I'm a bit new to Unity, so im asking for you guys help.
How can i check if the Scene == "gamescene"?
I tried something like this:
if(SceneManager.loadedScene == "gamescene") { do something }
I want to do an auto save only if the opened scene is the "gamescene".
But i haven't seen it working..
Your logic is right, but you should use SceneManager.GetActiveScene().name.
Your need to use SceneManager.GetActiveScene() then get the name of the scene from it.
if (SceneManager.GetActiveScene().name == "gamescene") { }

monotouch rotate in landscapemode and portrait mode

i am new to iPad developer,
i have created two or three iPad application in objective c using Xcode 4.
but now i want to create iPad application using Monodeveloper tool in C# language...
in which, i want to shift my tableView in orientation,
i searched in google but i didn't got any syntax.
for detail see my screen shot...
in first image (portrait mode) my Table is at extremeLeft , in second image (landscape mode) i want my table to be at extreme right..
how should i do this ?
i created tableview programatically, here is the code snippet,
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
Gainer(); //method call
UITableView Table=new UITableView();
Table.Frame=new RectangleF(20,200,400,400);
Table.Source=new TableViewDataSource(TopGainer); //passing parameter to tableview datasource
this.View.AddSubview(Table);
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
// Return true for supported orientations
return true;
}
Any help will be appreciated.
Thanks In Advance !!
You can override the WillRotate method and apply the exact position you want, in every case, based on the values that UIScreen.MainScreen provides. E.g.
public override void WillRotate (UIInterfaceOrientation toInterfaceOrientation, double duration)
{
switch (toInterfaceOrientation) {
case UIInterfaceOrientation.LandscapeLeft:
case UIInterfaceOrientation.LandscapeRight:
Table.Frame = new RectangleF (UIScreen.MainScreen.Bounds.Width - 20 - Table.Frame.Width, 200, 400, 400);
break;
case UIInterfaceOrientation.Portrait:
case UIInterfaceOrientation.PortraitUpsideDown:
Table.Frame = new RectangleF (20, 200, 400, 400);
break;
}
base.WillRotate (toInterfaceOrientation, duration);
}