- Home /
Android camera change based on orientation.
I'm looking for the most simple way to check to see if the orientation of the phone or tablet was changed, if it was switch to another camera. I've searched a great deal, and I've attempted to create my own, but I don't seem to understand it. This is what I made.
var camera1:Camera;
var camera2:Camera;
function Start(){
camera1.enabled = true;
camera2.enabled = false;
}
function Update(){
if (Screen.orientation(ScreenOrientation.Landscape)) {
camera1.active = true;
camera2.active = false;
}
}
Answer by Khada · Mar 12, 2013 at 03:41 PM
Judging from the reference page it should be:
if(Screen.orientation == ScreenOrientation.Landscape)
//...
else
//...
You might want to do look at some tutorials on enums to better understand how they work.
Hi, I've basically found this code somewhere else and changed it for what I need, I've done exactly as you've stated for the if statement, however this eror shows up "Assets/screen.js(12,17): BCE0044: expecting :, found '='." the line is camera1.enabled = true;
If what I've posted is the correct answer, you should mark it as answered. If it's not and you've found the answer yourself, you can post and mark your own answer. This is to keep the site clear, and so contributors can see that the question is answered, and others can benefit from the answer etc.
The error you mention is a syntax error. If you post the offending code I can tell you exactly what's wrong.
var camera1:Camera;
var camera2:Camera;
function Start(){
camera1.enabled = true;
camera2.enabled = false;
}
function Update(){
if (Screen.orientation == ScreenOrientation.Landscape){
camera1.active = true;
camera2.active = false;
}
}
That error doesn't look like it's for that block of code. Is that the entire contents of your Assets/screen.js script?
Also, you should be using camera.enabled ins$$anonymous$$d of camera.active.
Sorry, I was using the code I had above, this is proper
var camera1:Camera;
var camera2:Camera;
function Start(){
camera1.enabled = true;
camera2.enabled = false;
}
function Update()
{
if (Screen.orientation == ScreenOrientation.Landscape);{
camera1.enabled = true;
camera2.enabled = false;
}
}
error: Assets/NewBehaviourScript.js(11,17): BCE0044: expecting :, found '='.
Your answer
Follow this Question
Related Questions
Android - Camera orientation 1 Answer
open camera on android with orientation? 1 Answer
Screenshot function not working properly ,it records button on UI ? 0 Answers
Detect Android Rear Camera 2 Answers
Native camera FOV? 0 Answers