Distance Learning

Playing Sounds in Unity

Keenan Gray
1 / 7

Unity supports a range of sound files[wav,mp3,etc]

I downloaded several ".wav" files from freesound.org, but you can also record your own sounds using your phone.  You should also install Audacity, an easy to use sound editing program.   

Start by dragging and dropping the sounds into a folder in the editor.


Code to place in "update script" assigned to the gameobject with the audiosource

  if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            GetComponent<AudioSource>().Stop();
            GetComponent<AudioSource>().Play();
        }


If you want multiple game objects to play sounds you can assign this script to each, with a few modifications

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Play : MonoBehaviour
{
    public KeyCode key;  
    // Start is called before the first frame update
    void Start()
    {
       
    }
    // Update is called once per frame
    void Update()
    {
          if (Input.GetKeyDown(key))
        {
            GetComponent<AudioSource>().Stop();
            GetComponent<AudioSource>().Play();
        }
    }
}

Then assign the key in the editor, as seen in the images above

Animation in Unity

Keenan Gray

Adding Materials

Keenan Gray
1 / 5

Intro to Unity Programming

Keenan Gray

The world's of Unity are made up of individual pieces called "GameObjects". Each game object has a collection of components that dictate its behavior. Using programming (scripting) these behaviors can be expanded and manipulated.


In the example script we are manipulating a property on the rigidbody. We are applying a force based on keyboard input.

more information about rigidbody https://docs.unity3d.com/ScriptReference/Rigidbody.html


more information about input

https://docs.unity3d.com/ScriptReference/Input.html

Installing Unity

Keenan Gray
1 / 15

Visit Unity 3D's Website

Snowman Video

Keenan Gray

Clayxels class walkthrough

Keenan Gray

Freesound files

Keenan Gray
20018__djfroyd__1-16-groovy-beat-and-stems.zip

Sample 1

Keenan Gray
20018__djfroyd__1-16-groovy-beat-and-stems.zip
351888__djfroyd__clap.wav
351889__djfroyd__bass.wav
351890__djfroyd__1-16-groove-synth.wav
351891__djfroyd__1-16-groove-beat.wav
351892__djfroyd__kick.wav
351893__djfroyd__hi-hat.wav

From freesound.org

Part 1: Drawing on the screen

Keenan Gray

Purpose: To introduce programming and use lines of code in order to manipulate a processing window.  We can see our changes to the code reflected in the editor.

Description: Processing's primary function is the ability to draw images on a screen. We can interact with, and manipulate these images via code.  There are variety of projects that can be created using processing including - interactive art pieces, video games, computer applications, and websites.

Instructions: In the desktop version of Processing or at https://editor.p5js.org/ enter the code seen below.

function setup() {
createCanvas(400, 400);
}

function draw() {
background(220);
}

This is the boilerplate code for your first ever program.