Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
9
Question by RDC · May 12, 2014 at 09:01 AM · c#androidcameraiphone

Open/Start Device Native Camera in Unity3D app using C# script, Without 3rd Party Plugins

Recently I started learning Unity3D with iOS and Android Platforms. and gone through bunch of resources to get basics of Unity3D and scripting language. Example : **Unity3D Beginner Scripting**

but still I am not able to start/open iPhone/Android device camera using C# script in my Unity3D application. everytime I found regarding Game object camera not device camera.

Can anyone please guide me in this, what is the Class name for Device Camera or How to initiate.

my C# script file is (OpenCamera.cs) :

 using UnityEngine;
 using System.Collections;
 
 public class OpenCamera : MonoBehaviour {
 
     // Use this for initialization
     void Start () 
     {
         Debug.Log ("Start function get called");
         //I want to start camera here
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }


Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DeveshPandey · May 02, 2015 at 09:09 AM 0
Share

if anyone want to do this by using plugin, then go for this plugin

http://u3d.as/content/devesh-pandey/camera-shot

Or more info http://unitydevelopers.blogspot.in/p/blog-page_13.html

avatar image sudha · Aug 06, 2015 at 03:19 PM 0
Share

hai i want to use ipad camera in my application and followed the steps as u suggested above but not able to launch camera...as soon as application is launched it is giving a pop up saying do u want to allow device cam..on clicking ok the popup disappeared but cam is not launched..do we need add any plugin..please help me on this thanks, sudha

3 Replies

· Add your reply
  • Sort: 
avatar image
28
Best Answer

Answer by RDC · Jun 17, 2014 at 11:48 AM

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 alt text

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

4.Select Main Camera in GameObject and

4.1change Transform via Inspector

Position X=0 Y=0 Z=0 Rotation X=0 Y=0 Z=0 Scale X=100 Y=100 Z=100

4.2change 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: alt text


screen shot 2014-06-17 at 5.26.32 pm.png (19.3 kB)
screen shot 2014-06-17 at 2.18.252 pm.jpg (182.2 kB)
Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image joerty · Mar 28, 2015 at 09:06 AM 0
Share

Thank you for this, this is great. I have a question I was hoping you could answer. I am trying to use what you wrote in C# and expand a little. I want the camera to scan words and bring my information bases on a database offline? Any idea where I could start, I am new to unity and still learning.

avatar image RJJ92 · Jun 09, 2015 at 09:52 AM 0
Share

@joerty You'd have to use an AR extension to recognize the words and then work on your application. I would suggest Vuforia.

avatar image chandan565 · Jul 13, 2015 at 12:51 PM 0
Share

Thank , But it is rendering opposite in case of LandscapeLeft or LandscapeRight. in one orientation it is working fine but different orientation it is co$$anonymous$$g opposite.

avatar image TheWarper · Jul 28, 2015 at 12:29 AM 0
Share

Brilliant! Thanks bro! ;D

If it's upside down for you, just scale the plane -1 in the x-direction or the corresponding dir - it will look upside down for an image in the editor (before running) but will come out correctly on the iPhone.

Also, make sure it isn't allowed to rotate -otherwise the output will be incorrect half the time. If you want to allow a rotate then you'll need a bit of extra code to handle that case.

avatar image alicanozer · Nov 26, 2015 at 03:47 PM 0
Share

QCARBehaviour and Image are not resolving

Show more comments
avatar image
9

Answer by Jacruz · Jan 04, 2016 at 02:24 PM

thanks! In Unity 5, change the line:

 plane.renderer.material.mainTexture = mCamera;

replace for:

 plane.GetComponent<Renderer>().material.mainTexture = mCamera;

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by branek42 · Aug 02, 2018 at 09:39 AM

Hello how switch back camera on front camera? help me pls

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Juanibaz · Aug 31, 2018 at 07:43 PM 0
Share

Hello branek42, I am just starting to review information about Unity and I found a tutorial that helps using the backCamera as you requested. https://www.youtube.com/watch?v=c6NXkZWXHnc

I hope it helps.

Regards Juan

avatar image DaniyarGilymov · Sep 19, 2018 at 06:22 AM 0
Share

WebCamDevice[] devices = WebCamTexture.devices;

for(int i =0; i

avatar image DaniyarGilymov · Sep 19, 2018 at 06:23 AM 0
Share

WebCamDevice[] devices = WebCamTexture.devices;

for(int i =0; i

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

48 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do you map touch points to world space? 1 Answer

iPhone joypad interfering with MouseLook 0 Answers

About ListItems in Unity3D 1 Answer

How does WebcamTexture work? 0 Answers

Created a Vertical game for iPhone / Android 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges