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 davidgraeme · Apr 22, 2013 at 10:14 AM · game objectstealth

Stealth - Chapter 1: 6. Game Controller...

Hi guys, I'm quite new here. I've always been more of a modeller/designer but am taking the plunge into programming and scripting which I am loving. I'm using JavaScript by the way.

I'm working my way through the Stealth tutorial series and have come across something that I don't understand. He makes a reference to the panic alarm music like this:

 private var panicAudio : AudioSource;                                       // Reference to the AudioSource of the panic msuic.

Which to my knowledge is just declaring a new variable of type AudioSource. (?) He later implements the variable:

 // ... and fade in the panic music.
         panicAudio.volume = Mathf.Lerp(panicAudio.volume, 0.8f, musicFadeSpeed * Time.deltaTime);

but I don't see anything that's linking the actual AudioSource of the child Game Object, which is called secondaryMusic.

What am I not understanding?

Here's the link: The Lesson and Code

Thanks so much guys, looking forward to your wisdom!

Comment
Add comment · Show 3
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 KiraSensei · Apr 23, 2013 at 02:13 PM 0
Share

Your link is out, can you update it ?

avatar image davidgraeme · Apr 23, 2013 at 04:37 PM 0
Share

Hi $$anonymous$$iraSensai, thanks for your comment. It seems that a few of the lessons (including the one my link leads to) is offline at the moment. Unfortunately I don't have the JavaScript code on my computer, but I do have the completed script file in C-Sharp which might help put it into more context:

 using UnityEngine;
 using System.Collections;
 
 public class DoneLastPlayerSighting : $$anonymous$$onoBehaviour
 {
     public Vector3 position = new Vector3(1000f, 1000f, 1000f);             

     public Vector3 resetPosition = new Vector3(1000f, 1000f, 1000f);    // The default position if the player is not in sight.
     public float lightHighIntensity = 0.25f;                            // The directional light's intensity when the alarms are off.
     public float lightLowIntensity = 0f;                                // The directional light's intensity when the alarms are on.
     public float fadeSpeed = 7f;                                        // How fast the light fades between low and high intensity.
     public float musicFadeSpeed = 1f;                                    // The speed at which the 
     
     
     private DoneAlarmLight alarm;                                        // Reference to the AlarmLight script.
     private Light mainLight;                                            // Reference to the main light.
     private AudioSource panicAudio;                                        // Reference to the AudioSource of the panic msuic.
     private AudioSource[] sirens;                                        // Reference to the AudioSources of the megaphones.
     
     
     void Awake ()
     {
         // Setup the reference to the alarm light.
         alarm = GameObject.FindGameObjectWithTag(DoneTags.alarm).GetComponent<DoneAlarmLight>();
         
         // Setup the reference to the main directional light in the scene.
         mainLight = GameObject.FindGameObjectWithTag(DoneTags.mainLight).light;
         
         // Setup the reference to the additonal audio source.
         panicAudio = transform.FindChild("secondary$$anonymous$$usic").audio;
         
         // Find an array of the siren gameobjects.
         GameObject[] sirenGameObjects = GameObject.FindGameObjectsWithTag(DoneTags.siren);
         
         // Set the sirens array to have the same number of elements as there are gameobjects.
         sirens = new AudioSource[sirenGameObjects.Length];
         
         // For all the sirens allocate the audio source of the gameobjects.
         for(int i = 0; i < sirens.Length; i++)
         {
             sirens[i] = sirenGameObjects[i].audio;
         }
     }
     
     
     void Update ()
     {
         // Switch the alarms and fade the music.
         SwitchAlarms();
         $$anonymous$$usicFading();
     }
     
     
     void $$anonymous$$usicFading ()
     {
         // If the alarm is not being triggered...
         if(position != resetPosition)
         {
             // ... fade out the normal music...
             audio.volume = $$anonymous$$athf.Lerp(audio.volume, 0f, musicFadeSpeed * Time.deltaTime);
             
             // ... and fade in the panic music.
             panicAudio.volume = $$anonymous$$athf.Lerp(panicAudio.volume, 0.8f, musicFadeSpeed * Time.deltaTime);
         }
         else
         {
             // Otherwise fade in the normal music and fade out the panic music.
             audio.volume = $$anonymous$$athf.Lerp(audio.volume, 0.8f, musicFadeSpeed * Time.deltaTime);
             panicAudio.volume = $$anonymous$$athf.Lerp(panicAudio.volume, 0f, musicFadeSpeed * Time.deltaTime);
         }
     }
 }
 
avatar image robertbu · Apr 23, 2013 at 05:04 PM 0
Share

In the C# code, line 30 initializes panicAudio.

1 Reply

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

Answer by KiraSensei · Apr 23, 2013 at 05:13 PM

The variable is valuated at this line :

 // Setup the reference to the additonal audio source.
 panicAudio = transform.FindChild("secondaryMusic").audio;

It finds a child called "secondaryMusic" in the game object containing this script. So every use of the variable panicAudio after this line calls a method or a variable of secondaryMusic.audio, which is an AudioSource.

Comment
Add comment · Show 2 · 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 davidgraeme · Apr 23, 2013 at 06:04 PM 0
Share

Of course! That makes total sense, I was just being an idiot. I stared at the code for 30 $$anonymous$$utes and somehow I just did not see that line. Thank you so much $$anonymous$$ira!

avatar image KiraSensei · Apr 23, 2013 at 06:09 PM 0
Share

This kind of things can happen to anyone working a lot on some code part, the obvious can be not so obvious ...

To avoid that kind of problem, you can use this method. It can seem stupid at first, but it can sometimes help you avoid some little bugs, or find obvious stuff when you do it correctly :)

Good luck with your game !

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

12 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

Related Questions

I cant download the stealth asset from the asset store 1 Answer

Raycast radius 1 Answer

Enemy Line of Sight Help Needed 2 Answers

Find a GameObject exactly in position Vector3(1,2,3)? 3 Answers

help with tunnel Game 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