Class Hours: 10:05 – 2:40
Mr. Bohmann | wbohmann@ewsd.org
10:05 Today’s Notes & Attendance
Week 32
- WorkKeys Graphic Literacy Testing for:
- Gabi – May 13th, 12:30PM, E109 (PreTech 1)
- Phoenix – May 14th, 10:15am, CTE Conference Room
- Bus Jump Practice – we’ll leave at 10:40 and head to where we got the bus for CCV
10:08 Monday Mail

10:10 Lighting in Unity Continued…
ProTip: When baking lighting, change to GPU and set the environment samples down for faster bake times – which is good for testing

We can also make lights out of gameObject by making them emissive. An emissive material will emit light on to other game objects if (and only if) those game objects are static. To make an emissive material work, we have to bake (render the lightmaps) to the scene. Let’s try.

Volumes are a great way to add nice effects to your scene. We can create post processing effects globally or locally. In order to render the post-processing effects, we’ll need to add a volume and the camera will see and prioritize the effect. Then we’ll create some volume effects either locally or globally depending on what your scene demands. Let’s look at some features. there too.
With the current URP or HDRP (we are using the URP) you don’t need to add Post Processing The camera will see the post processing.

Assignment: Using your Modeling skillsets with Blender or ProBuilder Tools, set up a static scene in Unity and create a nice rocky path illuminated. Use materials and lighting in Unity for your scene. Don’t forget the work we did with terrain tools. Remember those? You’ll have to add from the package manager. Render as a nice .jpg. Assignment is due on Tuesday, May 20th.
Light Flicker Code
using UnityEngine;
using System.Collections.Generic;
// Written by Steve Streeting 2017
// License: CC0 Public Domain http://creativecommons.org/publicdomain/zero/1.0/
/// <summary>
/// Component which will flicker a linked light while active by changing its
/// intensity between the min and max values given. The flickering can be
/// sharp or smoothed depending on the value of the smoothing parameter.
///
/// Just activate / deactivate this component as usual to pause / resume flicker
/// </summary>
public class LightFlickerEffect : MonoBehaviour
{
[Tooltip("External light to flicker; you can leave this null if you attach script to a light")]
public Light light;
[Tooltip("Minimum random light intensity")]
public float minIntensity = 0f;
[Tooltip("Maximum random light intensity")]
public float maxIntensity = 1f;
[Tooltip("How much to smooth out the randomness; lower values = sparks, higher = lantern")]
[Range(1, 50)]
public int smoothing = 5;
// Continuous average calculation via FIFO queue
// Saves us iterating every time we update, we just change by the delta
Queue<float> smoothQueue;
float lastSum = 0;
/// <summary>
/// Reset the randomness and start again. You usually don't need to call
/// this, deactivating/reactivating is usually fine but if you want a strict
/// restart you can do.
/// </summary>
public void Reset()
{
smoothQueue.Clear();
lastSum = 0;
}
void Start()
{
smoothQueue = new Queue<float>(smoothing);
// External or internal light?
if (light == null)
{
light = GetComponent<Light>();
}
}
void Update()
{
if (light == null)
return;
// pop off an item if too big
while (smoothQueue.Count >= smoothing)
{
lastSum -= smoothQueue.Dequeue();
}
// Generate random new item, calculate new average
float newVal = Random.Range(minIntensity, maxIntensity);
smoothQueue.Enqueue(newVal);
lastSum += newVal;
// Calculate new smoothed average
light.intensity = lastSum / (float)smoothQueue.Count;
}
}
10:50 Morning Break (10 minutes)

11:00 GMetrix Coursework

11:40 Game Publishing – Unity Play
Let’s work through the process of taking whatever you have for your Breakout inspired game and see how publshing through Unity works. I have a dropbox for you to share your link. While our games may not be perfect – I am looking for the core deliverables and publishing to complete the grade.
11:55 Accessing Scripts & Variables on other Game Objects

Your game logic may require scripts to interact with each other. How can one script on one GameObject get a reference to another script on a different GameObject during the game? Scripts are attached by a component so we just need to figure out how to access those game objects. Let’s try this out.
Let’s start by making a new scene – call it WorkingTwoSripts
- Create a Triangle Sprite
- Create a Square Sprite
- Create Two Scripts (name them:)
- Triangle Script
- Square Script
- Attach each script to the corresponding game objects
Now let’s write some code
First, let’s Add an audio clip to our project (there is one in Public Folders) and then add the Audio Source component to our Square
Then let’s open the Square Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SquareScript : MonoBehaviour
{
public AudioSource audioSrc; //to reference an audio clip
public int score = 0;
public bool puppyIsCute = false;
public void FunkySound()
{
audioSrc.Play();
Debug.Log("The SoundScript was called");
}
public void MakeTrue()
{
puppyIsCute = true;
}
public void SetScore()
{
score++;
}
}
Be sure to plug in the AudioSource component (or drag the Square game object to our new public variable slot in the inspector)
Then, let’s open the Triangle Script.
The first thing we need to do is create a reference to the script (and game object) that has the script we want to access. We’ll do this by making a variable that stores the script information.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TriangleScript : MonoBehaviour
{
public SquareScript squareScrpt; // this creates a reference to Square Script
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("space"))
{
squareScrpt.FunkySound();
Debug.Log("audio is playing");
squareScrpt.MakeTrue();
Debug.Log("My Pupply is cute: " + squareScrpt.puppyIsCute);
squareScrpt.SetScore();
Debug.Log("The Score is: " + squareScrpt.score);
}
}
}
Pretty cool. By using the dot operator (.) we can access variables like score, the boolean and we can access methods.
Now you try – create a method of your own. Make sure it is set to Public. Try making a variable too.
Bonus: Headers and Tool Tips
[Header("Variables")]
[Tooltip("Explains what your variable is about")]
12:25 Lunch
12:55 Independent Reading

1:20 Afternoon Break (10 minutes)

1:30 Speed Design

1:50 Independent Production & Guided Support
- Past Due Work
- Environmental Lighting Assignment (rocky path)
2:38 Dailies
