Immersive Environments: Atmosphere

Oh Noe! My Inspector Window is Gone

In case your Inspector window gets hidden or closed for some reason:

  • You can find it under Window > General > Inspector.
  • This video shows how to do this. I found this video by Googling “inspector window not showing in unity”.

Adding an environmental sound to an object:

  • Create an object, such as a cylinder, 3D model, etc.
  • In the Inspector window for that object, select Add Component > Audio > Audio Source.
  • Drag an audio file into your Assets folder. Even better if you put it in Assets > Sound. Here’s a river loop MP3 (500K) in case you need something quick to test with.
  • Drag the audio file icon from the Assets panel into the AudioClip field in the Inspector.
  • Also in the Inspector for the Audio Component, check (✓) the boxes for “Play on Awake” and “Loop”.
  • Set the “Spatial Blend” to 3D (1.0), not 2D (0.0)
  • In the Audio Component inspector, open up the field for 3D Sound Settings, and set the “Volume Rolloff” to Linear, and set the Min Distance to 1 and Max Distance to 4. (Of course you can change these later.)
  • Play your game. You should hear the river when your avatar gets close to the Cylinder.


Triggering a Bonk Sound on Collision with an Object

Adding triggered audio to an object is more complex and requires a small script.

  • Here’s a bonk audio clip. Download it and drag it into the Assets of your Unity project.
  • Add a cube to your environment; rename it BonkCube.
  • Make sure that BonkCube has a Box Collider (adding it if necessary using Add Component > Physics).
  • In the inspector for the BonkCube’s Box Collider, ensure that Is Trigger is checked (✓).
  • Click the Add Component in the BonkCube’s inspector and add an Audio Source.
  • Drag the bonk audio clip from Assets into the AudioClip field of the Audio Source Component.
  • Make sure that Loop and PlayOnAwake are unchecked. Set the Spatial Blend to 1.0 (3D).
  • Create a script in your Assets folder; title it PlayOnCollision.cs (the exact title is essential). Open the script and paste in the code shown below.
  • Drag the PlayOnCollision script from your Assets into the Inspector window for BonkCube.
  • In the Inspector properties for that BonkCube’s script, click the ʘ button for the AudioSource field and set BonkCube to be the AudioSource.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayOnCollision : MonoBehaviour {
    public AudioSource audioSource;
    void OnTriggerEnter(Collider other){
        audioSource.Play();
    }
}

More information on adding Audio to Unity can be found in Prof. Pedercini’s tutorial:


Quick Demonstrations:

  • Add a Directional light, changing its position, rotation, color, strength, and shadow type.
  • Let’s make a custom skybox shader. Create a new material, name it MySkyBox; in its Inspector, change its shader type to Skybox, and select Procedural from the dropdown menu. Fiddle with the sliders to change its color, etc. This is explained in this video.

Some Projects by Former Students

Fall 2022:

Other semesters: