Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by PelusoWarro · Sep 05, 2017 at 09:01 AM · cameraflashlight

Flashlight + Camera view Problem

Hello guys i am making an online Qr scanner using this pluggin: https://github.com/kefniark/UnityBarcodeScanner the scanner works amazingly, the best i have seen, but on my case, i have an external problem, the LIGHT. i have to do the scan on some places where the ilumination is not good at all. the proper solution would be using the phone flashlight ( or torch).

 void Start () {
         
         anim = menuDesplegable.GetComponent<Animator> ();
     
         DontDestroyOnLoad (gameObject);
 
         // Create a basic scanner
         BarcodeScanner = new Scanner();
         BarcodeScanner.Camera.Play();
 
         // Display the camera texture through a RawImage
         BarcodeScanner.OnReady += (sender, arg) => {
             // Set Orientation & Texture
             Image.transform.localEulerAngles = BarcodeScanner.Camera.GetEulerAngles();
             Image.transform.localScale = BarcodeScanner.Camera.GetScale();
             Image.texture = BarcodeScanner.Camera.Texture;
 
             // Keep Image Aspect Ratio
             var rect = Image.GetComponent<RectTransform>();
             var newHeight = rect.sizeDelta.x * BarcodeScanner.Camera.Height / BarcodeScanner.Camera.Width;
             rect.sizeDelta = new Vector2(rect.sizeDelta.x, newHeight);
         };
 
         // Track status of the scanner
         BarcodeScanner.StatusChanged += (sender, arg) => {
             TextHeader.text = "Status: " + BarcodeScanner.Status;
         };
     }
 
     /// <summary>
     /// The Update method from unity need to be propagated to the scanner
     /// </summary>
     void Update()
     {
         if (BarcodeScanner == null)
         {
             return;
         }
         BarcodeScanner.Update();
 
         //
         if (Input.GetKeyDown ("space")) 
         {
 
             StartCoroutine ("Getname", "uhgaTV2V22");
             //Getname("bTZ58c4uwg");
         
         }
 
     }
 
     #region UI Buttons
 
     public void ClickStart()
     {
         if (BarcodeScanner == null)
         {
             Log.Warning("No valid camera - Click Start");
             return;
         }
 
         // Start Scanning
         BarcodeScanner.Scan((barCodeType, barCodeValue) => {
             BarcodeScanner.Stop();
             TextHeader.text = "Found: " + barCodeType + " / " + barCodeValue;
 
             // Feedback
             Audio.Play();
             // consulta a la base de datos
         //    InsertQR(barCodeValue);
             StartCoroutine ("Getname", barCodeValue);
 
 
             #if UNITY_ANDROID || UNITY_IOS
             Handheld.Vibrate();
             #endif
 
             BarcodeScanner.Stop();
         });
     }
 
     public void ClickStop()
     {
         if (BarcodeScanner == null)
         {
             Log.Warning("No valid camera - Click Stop");
             return;
         }
 
         // Stop Scanning
         BarcodeScanner.Stop();
     }
 
     public void ClickBack()
     {
         // Try to stop the camera before loading another scene
         StartCoroutine(StopCamera(() => {
             SceneManager.LoadScene("Boot");
         }));
     }
 

this is the code which is working 100% nicely. If i want to turn on the light, i use this:

     void FL_Start()
     {
         AndroidJavaClass cameraClass = new AndroidJavaClass("android.hardware.Camera");       
         WebCamDevice[] devices = WebCamTexture.devices;
 
         int camID = 0;
         camera1 = cameraClass.CallStatic<AndroidJavaObject>("open", camID);
 
         if (camera1 != null)
         {
             AndroidJavaObject cameraParameters = camera1.Call<AndroidJavaObject>("getParameters");
             cameraParameters.Call("setFlashMode", "torch");
             camera1.Call("setParameters", cameraParameters);
             camera1.Call("startPreview");
             Active = true;
 
         }
         else
         {
             Debug.LogError("[CameraParametersAndroid] Camera not available");
         }
 
     }
 
     void OnDestroy()
     {
         FL_Stop();
     }
 
     void FL_Stop()
     {
 
         if (camera1 != null)
         {
             camera1.Call("stopPreview");
             camera1.Call("release");
             Active = false;
         }
         else
         {
             Debug.LogError("[CameraParametersAndroid] Camera not available");
         }
 
     }
 
     public void Torch()
     {
         
         if (torchOn)
         {
             FL_Stop();
             torchOn = false;
         } 
         else 
         {
             FL_Start();
             torchOn = true;
         }
 
     }
 

This code also works 100% nicely for turning on the flashlight. but when i want to use both at same time, once the light is on, the raw image used to display the camera view freezes..

I have been struggling for some time with this.. i would love some captain suggestions :D thanks in advance

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by golu994 · Apr 02, 2018 at 06:52 AM

Hi, @PelusoWarro Warro I am also getting the same problem. Did you find any solution to this problem? Please help am also stuck on this for many days.

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 msevilla_unity · Nov 05, 2018 at 06:26 PM

Same problem here, i google it everywhere... no luck

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 SniperED007 · Mar 28, 2019 at 02:39 PM

Anybody find a solution to this yet?

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

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

107 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 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 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 I make the flashlight wobble as I walk? 1 Answer

How to access the light component on a camera object? 1 Answer

Flashlight Flare 3 Answers

How to make camera position relative to a specific target. 1 Answer

Set Flashlight mode to be off as default 1 Answer


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