Skip to content
Cawd Logo GAWD
  • Home
  • About
  • Assignments
  • Resources
  • Contact

Monday, May 8th

Monday, May 8th

Class hours: 9:40 – 2:05
Mr. Bohmann
wbohmann@ewsd.org

Week Thirty Three

Today’s Notes

  • Today is an EHS B Day
  • Last week’s rollerball prototypes
    • – click to play each other’s games this morning
  • SkillsUSA – Meeting tomorrow at 5:30pm
    • Garret & Emma
    • Hayden & Finn
    • Professional Development Test – May 26 at 10:am
    • Update your Resumes

9:40 Monday Mail

9:45 Quick AM Sprint

  • 20% – submitted to Classroom – Review talking points
  • Book Covers – Google Classroom – Mini Book Report

9:55 20% Showcase

presenting in front of group

Alphabetical Order

The dropbox for projects is in Google Classroom.

When presenting: Three Questions to respond to:

  1. What did you learn this week?
  2. What are you working on/showing us?
  3. What are your next steps? Where do you go from here? / What are you working towards?

10:35 Break

10:45 English with Mx. Yopp

11:30 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:45 Independent Reading

book covers

1:10 Break

1:20 Independent Project Worktime of Individual Support

  • Book Covers – due today
  • 20% for this week

1:58 Dailies – Let’s see what you’ve been working on

GAWD Instructors:

Matt Cronin

Will Bohmann

Instragram Facebook Twitter

A little about GAWD:

Serving high school students interested in Gaming, Animation, and Web Development in North Western Vermont.

Students continue at:

University of Vermont Ringling School of Art and Design Northeastern University Rochester Institute of Technology Concordia University

Students find careers at:

Dealer.com Union Street Media Rovers North Prudential Investments DockYard
Navigate to top of page