Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open device camera for iPhone and Android in Unity3d

I am working an application in which i need to open device camera in full view and i am making this app for both iOS and Android. So can any one tell me that how can i open full screen device camera in Unity for all devices Android and iPhone. This will be great help for me. Thanks in advance.

like image 929
josh Avatar asked Dec 31 '12 11:12

josh


People also ask

How do I switch between cameras in Unity?

We first start by deciding on the condition we use to change the camera. For now we'll use Input buttons 1, 2 and 3 to switch between cameras. We go into Project Settings -> Input Manager and add three new items to the list, which we'll label Switch1, Switch2, and Switch3. Each correspond to the button on the keyboard.

Can I take a photo in Unity using the device's camera?

Yes, You can. I created Android Native camera plugin that can open your Android device camera, capture image, record video and save that in the desired location of your device with just a few lines of code.


3 Answers

After some more digging on Google and Official docs. I got solution which I am going to share with you , It help someone .. someday..

1.Create New Project.

2.Select Main Camera in GameObject and change Transform via Inspector

Position X= -90 Y=785 Z=0 Rotation X=90 Y=90 Z=0 Scale X=1 Y=1 Z=1

enter image description here

3.Now go to GameObject — > Create Other — > Plane.

4.Select Main Camera in GameObject and

4.1 change Transform via Inspector

Position X=0 Y=0 Z=0 Rotation X=0 Y=0 Z=0 Scale X=100 Y=100 Z=100 enter image description here

4.2 change Tag=Player

Now create a c# script with name “CameraController” and replace the code with below one

using UnityEngine;
using System.Collections;

public class CameraController : MonoBehaviour
{
        public WebCamTexture mCamera = null;
        public GameObject plane;

        // Use this for initialization
        void Start ()
        {
                Debug.Log ("Script has been started");
                plane = GameObject.FindWithTag ("Player");

                mCamera = new WebCamTexture ();
                plane.renderer.material.mainTexture = mCamera;
                mCamera.Play ();

        }

        // Update is called once per frame
        void Update ()
        {

        }
}

5.Finally save and Drag this Script file onto “Plane” GameObject

Note - you may see preview rotated in Unity Game view but on RealDevice it works well. tested on iPhone5 and Android - Nexus 5.

Here is the snap shot how it comes if you change rotation angle to 180: enter image description here

like image 133
swiftBoy Avatar answered Oct 17 '22 20:10

swiftBoy


If you mean you want to use the camera to take and save photographs, I'd recommend Prime31's iOS and Android plugins. Unfortunately the Etcetera plugin is us$65 per platform, but I've used them both and they work great.

http://u3d.as/content/prime31/i-os-etcetera-plugin/2CU

http://u3d.as/content/prime31/android-etcetera-plugin/2CY

If you just want to show the camera's live output inside of your app's scene, you can create a plane and use a WebCamTexture to display the camera's live video output.

http://docs.unity3d.com/Documentation/ScriptReference/WebCamTexture.html

like image 6
Calvin Avatar answered Oct 17 '22 19:10

Calvin


There is a toolkit available to open the device camera in unity for iOS and Android called CameraCaptureKit - (https://www.assetstore.unity3d.com/en/#!/content/56673)

All the source is available and it has a plain and and simple plug'n'play demo as with Unity UI - it solves some of the obstacles involved with taking still images using the camera on your device.

Since the WebCamTexture is a generic solution to taking still images it doesn't enable sharpening of the images, the quality as well is more low-res on iOS since it uses a configuration for capturing real time video.

If you want to turn on flash / torch there you can do that with the toolkit.

like image 1
Chris Avatar answered Oct 17 '22 20:10

Chris