Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 collinsag · Sep 23, 2013 at 05:28 PM · lightflashlightambient light

Nothing should be seen without the flashlight pointing at it.

I'm trying to make a game working with the idea of echolocation. We are connecting a mic to Unity and sounds will enable the flashlight to turn on and off. The volume and duration of the sound will determine the intensity and range of the light. We've created a black environment with white outlines so that even when the light shines on it all you can really see are the edges of our objects and environments. So far so good. The issue we seem to be running into is that even with a black terrain, a black skybox and no other light sources, the outlines can still be seen even when the light is turned off. We've tried completely turning down the ambient light and jacking up the intensity of our spotlight, but when we do that nothing can be seen whatsoever, even with the spotlight. Are we just missing something, or is there something special we need to do to solve this issue?

My programmer also just mentioned he's having issues with the script he's using. The script is having difficulty getting access to the variable of the light. If anyone has any answers for that as well it'd be much appreciated!

 using UnityEngine;
 using System.Collections;
 
 public class Audio : MonoBehaviour
 {
     Light l;//Need to determine how this will be accessed
     GameObject o;
     int qSamples = 256;
     float refValue = 0.1F;
     float rmsValue;
     float dbValue;
     float pitchValue; 
     private float[] sample; // audio samples
     private float[] spectrum; // audio spectrum
     
     
     void Start ()
     {
 //        o = //UnityEngine.GameObject.FindGameObjectWithTag("First //Person Controller");
         l = (Light)(o.GetComponent("Light"));
         audio.clip = Microphone.Start("Built-in Microphone", true, 1,44100);
         audio.Play();
         sample = new float[qSamples];
         spectrum = new float[qSamples];
         
         
     }
 
     
     void Update ()
     {
         if (audio.isPlaying)
         {}
         else if (audio.clip.isReadyToPlay)
         {
             audio.Play();
             l.enabled = true;
         }
         else
         {
             audio.clip = Microphone.Start ("Built-in Microphone", true, 10,44100);
         }
         //FIGURE OUT ALGORITHM FOR AMOUNT OF LIGHT AND RANGE
     
         //float y = audio.GetSpectrumData(128,0,FFTWindow.BlackmanHarris)[64]*1000000;
         AnalyzeSound();
         if (dbValue < 5)
         {
             l.enabled = false;
         }
         else if (dbValue < 30)
         {
             l.range = 9;
         }
         else if (dbValue < 60)
         {
             l.range = 30;
         }
         else if (dbValue < 100)
         {
             l.range = 80;
         }
         
         
     }
     
     void AnalyzeSound()
     {
         audio.GetOutputData(sample, 0); // fill array with samples
         int i;
         float sum = 0;
         for (i=0; i < qSamples; i++)
         {
             sum += sample[i]*sample[i]; // sum squared samples
         }
         rmsValue = Mathf.Sqrt(sum/qSamples); // rms = square root of average
         dbValue = 20*Mathf.Log10(rmsValue/refValue); // calculate dB
         if (dbValue < -160) dbValue = -160; // clamp it to -160dB min
     }
     
     
     
     
 }

The script is attached to a First Person Controller and the Spot Light is attached to the First Person Controller too. There is a diffuse shader being used.

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 tanoshimi · Sep 23, 2013 at 06:53 PM 0
Share

What shader is assigned to the environment material? And what's the code in the script that is having "difficulty"?

avatar image recon472 · May 20, 2014 at 04:52 PM 0
Share

do you have your camera background color set to black?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · May 20, 2014 at 05:14 PM

Usually when questions similar to yours come across the list the answer is changing the settings of Ambient Light:

 Edit > Render Settings > Ambient Light

Change the color to black for this setting.

As for the second issue, you'll need to programmer to post a new question explaining in more detail. I see one potential thing you might want to improve. Use the generic version of GetComponent() instead of the string version.

 l = o.GetComponent<Light>();

But what he is doing should not cause problems as long as 'o' has a light component.

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

17 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

Related Questions

Flashlight battery script 3 Answers

Flash light off on start 1 Answer

How do I get my flashlight to work? 1 Answer

Flashlight Flicker! 2 Answers

Using shuriken to create volumetric lights effect 5 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