Code Challenge 2

Содержание

Слайд 2

Create a script called Spawner

Spawner script level 1
Have the spawner instantiate prefab

Create a script called Spawner Spawner script level 1 Have the spawner
-GameObjects every frame. A standard Cube or some other primitive is fine.

Слайд 3

Spawner / prepare to instantiate by the manager

Spawner script level 2
Move the

Spawner / prepare to instantiate by the manager Spawner script level 2
instantiating to a separate method that is public. Let’s call it Spawn.
Create a variable like ‘numberSpawned’ that tracks the amount of objects instantiated. Point is to be able to call instantiating from another script.

Слайд 4

Create a script called SpawnManager

SpawnManager script level 1
Have a reference to your

Create a script called SpawnManager SpawnManager script level 1 Have a reference
Spawner and call its Spawn -method in every update. The point is to move the spawning logics from Spawner to SpawnManager.

Слайд 5

SpawnManager / spawn timer

SpawnManager script level 2
Create a timer for spawning, where

SpawnManager / spawn timer SpawnManager script level 2 Create a timer for
you can set the delay between spawns in seconds. You could start with half a second. Point is to be able to control spawning speed from inspector and not rely on the fps of the machine.

Слайд 6

Spawner / spawn position and parent

Spawner script level 3
Make the spawned prefabs

Spawner / spawn position and parent Spawner script level 3 Make the
instantiate where this spawner GameObject’s position is. Make sure it’s on a separate object from the SpawnManager.
Make the spawned prefabs childs of this GameObject. The point is to have spawned objects appear where this GameObject is.

Слайд 7

Spawner / make spawned objects jump

Spawner script level 4
Add a Rigidbody to

Spawner / make spawned objects jump Spawner script level 4 Add a
your prefab -GameObject.
When this GameObject is spawned, tell the Rigidbody to jump by something like: AddForce(Vector3.up * jumpForce, ForceMode.Impulse)
You might want to add a plane or some kind of floor at this point. The point is to have fun.

Слайд 8

SpawnManager / support multiple spawners

SpawnManager script level 3
Prepare your SpawnManager for controlling

SpawnManager / support multiple spawners SpawnManager script level 3 Prepare your SpawnManager
multiple spawners: change the reference to your Spawner into a list of Spawners.
Change your Spawn -calls to call on every spawner. (hint: use loop)
Make sure your spawning still works, you can drag your Spawner -script manually. Point is to support multiple spawners.

Слайд 9

Spawner / random chance

Spawner script level 5
Add a random chance of 20%

Spawner / random chance Spawner script level 5 Add a random chance
for Spawners to instantiate.
The point is to add randomness.

Слайд 10

SpawnManager / Singleton

SpawnManager script level 4
Create a singleton -reference to the SpawnManager

SpawnManager / Singleton SpawnManager script level 4 Create a singleton -reference to
in the script (hint: static).
The point is to find the manager with any script in the scene.

Слайд 11

SpawnManager / subscribe 1

SpawnManager script level 5
Create a Subscribe -method in the

SpawnManager / subscribe 1 SpawnManager script level 5 Create a Subscribe -method
script that accepts a Spawner as a parameter and then adds the GameObject to the list of Spawners.
Clear the list of manually assigned Spawners. You may need to initialize the list in Awake with spawners = new List()
Prepare to accept subscriptions from managed scripts.

Слайд 12

Spawner / subscribe 2

Spawner script level 6
Make this Spawner subscribe to SpawnManager

Spawner / subscribe 2 Spawner script level 6 Make this Spawner subscribe
automatically. Make sure this is after the manager initializes its singleton.
Duplicate and scatter 6 Spawner -GameObjects around your scene.
Make sure they all start spawning without you having to assign them on the SpawnManager list that should be empty now.
Complete the subscription from this end.

Слайд 13

SpawnManager / spawn cap

SpawnManager script level 6
Make your Spawner / ‘numberSpawned’ a

SpawnManager / spawn cap SpawnManager script level 6 Make your Spawner /
static member so every spawn by any spawner is recorded.
Create a variable for SpawnManager that controls the maximum amount of spawned objects. When it’s reached (hint: read from Spawner), no more is spawned.
Limit your spawned objects.

Слайд 14

UI

UI script level 1
Create UI where you have a button that starts

UI UI script level 1 Create UI where you have a button
and stops the spawning.
Control your spawns.

Слайд 15

UI

UI script level 2
Create UI that shows the amount of cubes spawned.
Observe

UI UI script level 2 Create UI that shows the amount of
your spawns.

Слайд 16

Spawner / random color

Spawner script level 7
Randomize your spawned object’s color.
It’s fun!

Spawner / random color Spawner script level 7 Randomize your spawned object’s color. It’s fun!

Слайд 17

SpawnManager / events

SpawnManager script level 7
Refactor your code to use events (like

SpawnManager / events SpawnManager script level 7 Refactor your code to use
Actions) instead of subscribing to list.
Events

Слайд 18

UI

UI script level 3
Make the binding happen in runtime (subscribe to event

UI UI script level 3 Make the binding happen in runtime (subscribe
or think of another way)
Automatic binding FTW
Имя файла: Code-Challenge-2.pptx
Количество просмотров: 40
Количество скачиваний: 0