1 of 15

Game Development �With Unity

Maris Stella �Robotics & Programming Club�2020

2 of 15

Review

  • Elemental Tetrad
    • Technology, Mechanics, Story, Aesthetics
    • Game samples
  • Unity 2D Platformer Review
    • TIlemaps / Tile Palette
    • Converting Sprites into Tiles
    • 2D Rigidbody & Colliders
    • Using scripts (Jiggler / Simple Trigger)

3 of 15

Today

  • Checkpoint - What are you working on?
    • Submit proof of work: �https://a9i.sg/files?class=ASi
  • Unity 2D Platformer Tutorial (Cont.)
    • C# Scripting / Visual Studio
    • SpawnPoint Checkpoints

4 of 15

CHECKPOINT - Assessment

  • Share your most interesting game edits
    • Share Screen
    • Build & Share game (follow built-in tutorial)
      • Copy URL into any text file
      • Submit file
    • Take a screen shot and save as file
      • Submit file
  • Share Assets You Found on the Internet
    • Submit tilesheet PNG or screenshot, or just URL and description of asset�
  • Submitting Files

5 of 15

C# Scripting

  • C# can be written by any text program (Notepad, TextEdit, Word, etc)
  • For color-coding and intellisense, on Windows I recommend:
    • Visual Studio
    • Atom
    • MonoDevelop
    • Notepad++
  • For MacOS follow instructions to setup Visual Studio here:�https://docs.unity3d.com/Manual/ScriptingToolsIDEs.html

6 of 15

C# Building

  • C# code gets built by Unity Editor environment when it senses a change
    • save file in Visual Studio
    • focus back on Unity Editor
    • you will see a pause
    • maybe some notices (errors, warnings) in the Console
    • and a ping at the end of the build

7 of 15

C# Basics

  • Object-Oriented
  • Class
  • Variables / Types (int, float, string)
    • Public/Protected/Private members
    • Public vs. SerializedField
  • Loops (for/while)
  • Conditionals (if/else)

8 of 15

Unity C# - Useful Basic Classes

  • MonoBehavior
    • Start()
    • Update()
      • FixedUpdate()
    • OnCollisionEnter(other)
    • OnTriggerEnter(other)�
  • Input
    • GetButtonDown()
    • mousePosition
    • gyro/location - useful on handhelds and specialized input devices
  • Debug
    • Debug.Log(“This goes into the console…” + someVariable);

9 of 15

Scripting Example: Change SpawnPoint

  • Create a GameObject with a 2D Collider (IsTrigger set)
  • Place it somewhere where player can collide with it…

You can choose whether to render a sprite, or to make this an invisible collision zone.

10 of 15

Scripting Example: Change SpawnPoint

  • Choose your object, and Add Component -> New Script
  • Call it something like “ChangeSpawnPoint”
  • When it shows up on your object, click on the right-hand 3 dots to “edit”

11 of 15

Scripting Example: Change SpawnPoint

  • You can delete Start & Update methods
  • We need to create a new one -

void onTriggerEnter2D(Collider2D other) �{

// Change the SpawnPoint’s position to this position, � // Whenever a Player collides with this...

}

12 of 15

Scripting Example: Change SpawnPoint

  • Make sure to acquire the SpawnPoint object

public GameObject spawnPoint;

void onTriggerEnter2D(Collider2D other) �{

// Change the SpawnPoint’s position, � // Whenever a Player collides with this...

}

13 of 15

Scripting Example: Change SpawnPoint

  • Change the spawnPoint’s position to the colliding object’s postition

public GameObject spawnPoint;

void onTriggerEnter2D(Collider2D other) �{

// Change the SpawnPoint’s position, � // Whenever a Player collides with this…� spawnPoint.transform.position = transform.position;

}

14 of 15

Scripting Example: Change SpawnPoint

  • Make sure only to do this on Player collision

public GameObject spawnPoint;

void onTriggerEnter2D(Collider2D other) �{� // Change the SpawnPoint’s position, � // Whenever a Player collides with this…� If (other.name == “Player”) {� spawnPoint.transform.position = transform.position;� }�}

15 of 15

Scripting Example: Change SpawnPoint

  • Add Debug statements, and test!