Presentation is loading. Please wait.

Presentation is loading. Please wait.

ROOM 2+ FEATURES A-CREEPIN’ BEFORE WE START: LANYARDS RECAP ALL HERE?

Similar presentations


Presentation on theme: "ROOM 2+ FEATURES A-CREEPIN’ BEFORE WE START: LANYARDS RECAP ALL HERE?"— Presentation transcript:

1 ROOM 2+ FEATURES A-CREEPIN’ BEFORE WE START: LANYARDS RECAP ALL HERE?
SPOT THE SPELLING MISTAKES!

2 GOALS By the end of the session you should: Discuss activity diagrams
Add new features to the walking simulator Experiment with variables Create your own activity diagram Pitch the next game mechanic

3 Activity diagrams can be used to help represent the flow of a program.
The key ACTIVITY DIAGRAM Activity diagrams can be used to help represent the flow of a program. In your games, they can help you make sense of behaviour and code for individual objects or specific functions. For example, the diagram on the right shows the behaviour of the key object. Player clicks on the key Destroy the key Rotate the door controlled by this key

4 The solid circle represents the starting point of the diagram.
The key ACTIVITY DIAGRAM The solid circle represents the starting point of the diagram. Consider this the entry point of your code – the start of a function or the beginning of the game logic. Player clicks on the key Destroy the key Rotate the door controlled by this key

5 Rounded rectangles show actions.
The key ACTIVITY DIAGRAM Rounded rectangles show actions. Actions are things that can potentially happen while your code/game is running. Player clicks on the key Destroy the key Award 5 points to the player Rotate the door controlled by this key

6 The key ACTIVITY DIAGRAM
A solid circle within another circle shows the end/exit point of the activity diagram. Exit points are reached when the flow through activities and decisions has finished. A complicated diagram could have multiple exit points to make it easier to read. Player clicks on the key Destroy the key Rotate the door controlled by this key

7 The key ACTIVITY DIAGRAM
Arrows show the flow through an activity diagram. They link the start and end points via actions and decisions. Arrows should be 1 directional. If actions and decisions need to be revisited, separate arrows are used to show the 2 way flow. Player clicks on the key Destroy the key Rotate the door controlled by this key

8 Let’s bring this diagram to life in code.
Flashlight ACTIVITY DIAGRAM Let’s bring this diagram to life in code. Load up your walking simulator! Player presses F Toggle the light’s intensity between 0 and 1

9 THE LIGHT Create a new Spotlight from the Light section of the GameObject menu. Make the light a Child of the camera in your first person controller. Change the light’s Shadow Type from No Shadows to Soft Shadows. You may wish to lower the Intensity of other lights in the scene.

10 CODE Create a new C# Script called Flashlight.
Add the script to the Spotlight. Load the script up in MonoDevelop.

11 VARIABLES Variables allow you to store information. As the name suggests, information in a variable can be changed. For Unity to be able to store some information, it needs to know what data type the information will be.

12 VARIABLES

13 VARIABLES Create a public variable in your new script by typing the following line just above its default Start function: public Light flashlight; Note: the data type of this variable is Light and the variable name is flashlight.

14 VARIABLES Save the script and select your Spotlight.
You should now be able to tell the Flashlight component which light to use, thanks to the public variable you made. Drag the Light component into the slot.

15 CODE Time to control that Flashlight.
Delete the Start function and add the following to the Update function: if (Input.GetKeyDown(KeyCode.F)) { // Flip the intensity between 0 and 1 flashlight.intensity = 1 - flashlight.intensity; }

16 IF What just happened?!

17 IF You just asked a question with code. More specifically, you asked if the player had pressed the F key down in this frame. If (or conditional) statements are a core part of coding and will let you make informed decisions in your game logic.

18 Diamonds represent decisions (ifs).
The key ACTIVITY DIAGRAM Diamonds represent decisions (ifs). Decisions should have (at least) 2 arrows directing away from them. These arrows are annotated to explain why they would be followed. Player clicks on the key Player near key Player far away Destroy the key Rotate the door controlled by this key

19 IF

20 The key BONUS: INVENTORY Slides from here are an optional bonus and can be found on the shared Google Drive. Use your time making sense of the new content, reading up on the more technical aspects and trying to code something new.

21 The key BONUS: INVENTORY Inventory Item Door Controller
Player clicks this door Inventory contains key item Inventory does not contain key item Player clicks on the key Rotate this door Destroy the item Destroy this script (not the whole game object) Add item to inventory

22 INVENTORY Create 3 new C# Scripts: Inventory - to store held items
InventoryItem - to control the items DoorController - controls doors with items

23 INVENTORY Inventory should be put on one main object (such as the player) and contains a single line of code to store all collected items: public List<string> items = new List<string>(); but it needs an extra using line too: using System.Collections.Generic;

24 INVENTORY InventoryItem is placed on collectible objects. The itemName variable is stored in the inventory list when this item is clicked on. public string itemName; void OnMouseDown() { // Find the Inventory controller Inventory inventory = GameObject.FindObjectOfType<Inventory>(); // Add this item to the inventory inventory.items.Add(itemName); // Destroy (pick up) this item Destroy(gameObject); }

25 INVENTORY DoorController is used on doors that require a specific inventory item to open. keyItemName must match one of the InventoryItem’s itemName variables or it will never open. See the next slide for the full code.

26 INVENTORY // The name of the object that controls this door
public string keyItemName; void Update () { // Find the InventoryController Inventory inventory = GameObject.FindObjectOfType<Inventory>(); // Does the inventory list contain the key item? if (inventory.items.Contains(keyItemName) == true) { // Rotate this door transform.Rotate(0,80,0); // Destroy this script Destroy(this); }

27 The key BONUS: INVENTORY Try this one! Door Controller
Player clicks this door Player is near the door Player is not near the door Inventory contains key item Rotate this door Destroy this script (not the whole game object) Inventory does not contain key item

28 SOLO Develop your walking simulator further. Consider:
Extra models - practice Matt’s stuff! Extra code - can you create your own components based on code to date? Experimentation! Play around with Unity’s features. Video tutorials, straight from Unity.


Download ppt "ROOM 2+ FEATURES A-CREEPIN’ BEFORE WE START: LANYARDS RECAP ALL HERE?"

Similar presentations


Ads by Google