Module 3 Examples:  Link to GitHub

Coverage

Unity specific skills you will need, practice, and demonstrate include:

·         User Interface

o   Sharing the editor between the GameObject world and the UI coordinate system

o   Working with UI RectTransform

·         Packages: create and import

 

Concepts you will explore and understand include

·         The lerp function: gradual rotation and chasing

·         Simple implementation of a finite state machine

·         Randomness and simple examples in games (again)

 

1.      User Interface and Packages: Example based on Module-2 Example-4

o    Run Behavior: press-space bar to launch egg at slider-bar-value interval

o    Packet Import:

§  Assets èImport Package: select SliderWithEcho.unitypackage

§  From the github look for ClassExample/Packages

§  PreFab: UI-SliderWithEcho

§  Scripts/UI/SliderWithEcho.cs

§  To create your own package, do the reverse: AssetsèExport and select the appropriate components (remember to select the necessary scripts)

o    UI: Using the imported package

§  Remember, first your scene must have a Canvas (create by: UIàCanvas)

§  To use: drag SliderWithEcho pre-fab into the Canvas:

1.      Align anchor: lower-left

§  Rename to: SpawnRate

§  Must configure: (Select SpawnRate and look in the Inspector Window)

1.      mLabelText

2.      SliderValue: (this is a Text UI object)

1.      Customize the text detail, e.g., color

3.      SliderBar (in the Slider component)

1.      Set:   Min Value, Max Value, Init Value

§  Careful: when adjusting positions of the SliderWithEcho object, do not adjust the children positions!

o    GreenArrowBehavior: reference an SliderWithEcho

§  In the editor: drag the entire SliderWithEcho (SpawnRate) to the GreenArrowBehaivor object

§  The value() of SpwanRate is how many seconds to wait in between spawning new eggs

§  Note: Time.time amount of seconds elapsed since the beginning of the game

o    Learned:

§  Almost all Unity specific:

§  Time.time: time (in seconds) after game began

§  Package: import/export of prefab watch to check all dependent components

§  Note the logic in GreeArrowBehavior::Update() on check for spawn rate.

o    Alternate implementation:

§  SpawnRateèSliderBar has a call back (event handler)

§  Can define a function in GreenArrowBehavior and add the function here.

1.      Pros: Receives value change via event, no need to refer in update()

2.      Cons: Implicit references (via event service functions), can be challenging to figure out all event handlers.

§  I usually poll UI events in Update() function.

§  Exercise:

§  Implement this alternative.

§  A wrap in the horizontal and truncate in the vertical may result in part of the message not shown!

§  Look for Horizontal Overflow, try different settings!

  1. Cool Down Bar: simple continuation from the previous example
  2. Gradual Rotation and Chasing
  3. Autonomous Movement with Randomness:
  4. Finite State Machine
  5. FSM + Randomness

§  Ease of expansion when well abstracted

  1. Orbiting