SlideShare a Scribd company logo
Lecture 2: C# Programming 

by Making Gold Miner Game
Dr. Kobkrit Viriyayudhakorn

iApp Technology Limited

kobkrit@iapp.co.th
ITS488 (Digital Content Creation with Unity - Game and VR Programming)
Troubleshooting
• Confuse? Read a manual at https://docs.unity3d.com/2017.1/
Documentation/Manual/UnityManual.html

• Get any problem? Google it: "DOING ANYTHING in unity"

Review: Writing Code in Unity
Right click at Project Window Name it as "ConsolePrinter"
Start writing a code
• Double Click at the ConsolePrinter.cs

• The MonoDevelop-Unity IDE will be show up and you can make the first
program.
Code structure
Printing a Text
Save and Go back to Unity
Create
a New
Game
Object
Right click Select
Rename + Enter
Inspect Window

on the right.
Attaching Script to A Game Object
1. Drag the
ConsolePrinter
script and drop
onto
ConsolePrinterGO
in Hierarchy
Window

2. Or Drag onto 

Inspector
Window
Start Running
• Click on Run Button

• Switch to Console Window, you will see "Hello World!" text.

Print Statement
Output Console
Variable #1: int
Output Console
Variable #2: int & float & string
Output Console
Variable #3: int & float oper.
Output Console
Variable #4: string & bool oper.
Output Console
Type Represents Range Default
Value
bool Boolean value True or False FALSE
byte 8-bit unsigned integer 0 to 255 0
char 16-bit Unicode character U +0000 to U +ffff '0’
decimal 128-bit precise decimal values with
28-29 significant digits
(-7.9 x 1028
to 7.9 x 1028
) / 100 to 28 0.0M
double 64-bit double-precision floating point
type
(+/-)5.0 x 10-324
to (+/-)1.7 x 10308
0.0D
float 32-bit single-precision floating point
type
-3.4 x 1038
to + 3.4 x 1038
0.0F
int 32-bit signed integer type -2,147,483,648 to 2,147,483,647 0
long 64-bit signed integer type -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
0L
sbyte 8-bit signed integer type -128 to 127 0
short 16-bit signed integer type -32,768 to 32,767 0
uint 32-bit unsigned integer type 0 to 4,294,967,295 0
ulong 64-bit unsigned integer type 0 to 18,446,744,073,709,551,615 0
ushort 16-bit unsigned integer type 0 to 65,535 0
if-else oper.
Output Console
Game Planning
• You are a gold miner and you want to find
a gold pit.

• You can move up, down, left, and right.

• Movement is a fixed distance.

• After each turn, your distance from the
gold pit is displayed.

• You win when you get the gold pit.

• Your score is how many turns it took.
Rough Pseudo Code
• Set Start Location

• Calculate distance from Gold pit.

• Print the distance 

• Read player’s move

• Update location from the Gold pit.

• Repeat.
Start Writing a Game Logic
Output Console
If we change loc = 10.3
Output Console
Rough Pseudo Code
• Set Start Location

• Calculate distance from Gold pit.

• Print the distance 

• Read player’s move

• Update location from the Gold pit.

• Repeat.
Input.GetKeyDown
Reading User Input
Output Console 

(After press left arrow couple times)
Make sure you select the Game tab

Before pressing the left key. ->
Adding more Keydown
Output Console 

(After press left+right arrow couple times)
* Make sure you select the Game tab

Before pressing the left key.
Update Location
Output Console
Variable Scope: loc
Scope of loc
Make it class variable
Scope of loc
Move the variable declaration from within

"Start()" Method to within "GoldMiner" class.

(Outer the "Start()" method)
Output Console
Class variable assignment
• Can not be the product from the
computation.

• Can be a constant or not
assignment at all.

• You can re-assign the class
variable in any function body.
Do Distance Calculation when a key is pressed.
Output Console
Now it is playable!
Too much duplicate code!
• Using a method /
function for repeatedly
run code.

• Make code much
shorter. Easier to
manage the code
structure.
Function!
• Return nothing, just
print the message out.

• Use "void" return type.

• Call it when you want to
re-calculate the
distance.

• Call it when you want to
print out the distance
result.
Create calculateDistance Function
Completed Game for 1D world.
Keep pressing
right arrow

Programming C# for 2D world
Vectors
X
(4,3)
y=3
x=4
(0,0)
Vectors Addition
a
b
a+b(0,0)
Vectors Reduction
a
b
a+b
-b
a-b
(0,0)
Finding Distance of Two Vectors
Gold

Miner
(0,0)
Gold

Pit
- Gold Miner + Gold Pit
Objects and Class
Class Car
Class = Template
Object = Product
new
Methods and Attributes
Converting from 1d to 2d
• Using the Vector2 instead of float (Don’t forget the new keyword)

• Update distance to be pathToGoldPit Vector2

• Compute the distance by using Vector2 magnitude property.

• Remove all non make-sense code (written for 1d world).
Converting from 1d to 2d
the magnitude of vector = the length of the vector
Converting from 1d to 2d
Since we could not compare less than and greater than in the Vector2 class,

the code in the block need to be removed, otherwise, the complication errors.
Update the location in Vector2
X Y
Testing
Haha! We forgot Up and Down button. We can not win!
Public variables
Inspector Panel
All public variable will be debuggable in the Inspector Panel.
You can change the value and 

see the change in real time!
Exercise I
• Implement Up and Down button, so the player can completed the game.

• Starting code is located at https://github.com/kobkrit/vr2017class/blob/
master/exercise1.cs
Glossary 1
Name Meaning Example
Value Numbers, text, etc. “Hello world”, 3.14f, 1
Type The “shape” of the value. int, float, string
Variable
The correctly typed box for the
values.
int anInteger;
Statement A command to the computer. print("hello")
Expression
A command that evaluates to a
value.
homeLocation - location

"Distance:" + distance
Glossary 2
Name Meaning Example
Method
A factory which something to
input to get output.
Input.GetKeyDown(...)
Arguments The inputs to a method KeyCode.RightArrow
Return value The output of a method if(Input.GetKeyDown(...))
Operation
Like a method but with an
operator rather than a name.
Often ‘infix’.
1 + 2
Glossary 3
Name Meaning Example
Object
A collection of variables with
values and methods that act on
those variables.
The actual house.
Class
The blueprint of the variables and
methods.
An architect's drawing of a
house.
Instantiation
The process of making an object
from a class.
new Vector2(2.0f, 3.0f)
Instance
Same as an object. Often used to
say “an instance of a class X”.
The actual house according to
drawings X.
Homework
• Can we print out the location into the console? 

• If we have multiple gold pits?

• If we have traps?

• When an user fells to the traps, GAME OVER!

More Related Content

What's hot

Unity - Building your first real-time 3D project
Unity - Building your first real-time 3D projectUnity - Building your first real-time 3D project
Unity - Building your first real-time 3D project
NexusEdgesupport
 
2d game engine workflow
2d game engine workflow2d game engine workflow
2d game engine workflow
luisfvazquez1
 
DSC RNGPIT - Getting Started with Game Development Day 1
DSC RNGPIT - Getting Started with Game Development Day 1DSC RNGPIT - Getting Started with Game Development Day 1
DSC RNGPIT - Getting Started with Game Development Day 1
DeepMevada1
 
Hands On with the Unity 5 Game Engine! - Andy Touch - Codemotion Roma 2015
Hands On with the Unity 5 Game Engine! - Andy Touch - Codemotion Roma 2015Hands On with the Unity 5 Game Engine! - Andy Touch - Codemotion Roma 2015
Hands On with the Unity 5 Game Engine! - Andy Touch - Codemotion Roma 2015
Codemotion
 
WP7 HUB_XNA overview
WP7 HUB_XNA overviewWP7 HUB_XNA overview
WP7 HUB_XNA overview
MICTT Palma
 
WP7 HUB_XNA
WP7 HUB_XNAWP7 HUB_XNA
WP7 HUB_XNA
MICTT Palma
 
Systematic analysis of GWAP
Systematic analysis of GWAPSystematic analysis of GWAP
Systematic analysis of GWAPShih-Wen Huang
 
Let's make a game unity
Let's make a game   unityLet's make a game   unity
Let's make a game unity
Saija Ketola
 
3d game engine
3d game engine3d game engine
3d game engine
luisfvazquez1
 
Future warfare
Future warfareFuture warfare
Future warfare
Andrea Prosseda
 
Academy PRO: Unity 3D. Scripting
Academy PRO: Unity 3D. ScriptingAcademy PRO: Unity 3D. Scripting
Academy PRO: Unity 3D. Scripting
Binary Studio
 
Programmers guide
Programmers guideProgrammers guide
Programmers guide
Karla Paz Enamorado
 
Green My Place Game7 Switch Search
Green My Place Game7 Switch SearchGreen My Place Game7 Switch Search
Green My Place Game7 Switch Search
Ben Cowley
 
Game development with Cocos2d-x Engine
Game development with Cocos2d-x EngineGame development with Cocos2d-x Engine
Game development with Cocos2d-x EngineDuy Tan Geek
 
38199728 multi-player-tutorial
38199728 multi-player-tutorial38199728 multi-player-tutorial
38199728 multi-player-tutorial
alfrecaay
 
Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8
Troy Miles
 
The purpose and functions of components of game engines
The purpose and functions of components of game enginesThe purpose and functions of components of game engines
The purpose and functions of components of game engines
JoshCollege
 
Lock And Key Initial Design Document
Lock And Key Initial Design DocumentLock And Key Initial Design Document
Lock And Key Initial Design Document
Ochuko Ideh
 
Getting started with Unity3D and Oculus Rift
Getting started with Unity3D and Oculus RiftGetting started with Unity3D and Oculus Rift
Getting started with Unity3D and Oculus Rift
Maia Kord
 

What's hot (20)

Unity - Building your first real-time 3D project
Unity - Building your first real-time 3D projectUnity - Building your first real-time 3D project
Unity - Building your first real-time 3D project
 
2d game engine workflow
2d game engine workflow2d game engine workflow
2d game engine workflow
 
DSC RNGPIT - Getting Started with Game Development Day 1
DSC RNGPIT - Getting Started with Game Development Day 1DSC RNGPIT - Getting Started with Game Development Day 1
DSC RNGPIT - Getting Started with Game Development Day 1
 
Hands On with the Unity 5 Game Engine! - Andy Touch - Codemotion Roma 2015
Hands On with the Unity 5 Game Engine! - Andy Touch - Codemotion Roma 2015Hands On with the Unity 5 Game Engine! - Andy Touch - Codemotion Roma 2015
Hands On with the Unity 5 Game Engine! - Andy Touch - Codemotion Roma 2015
 
WP7 HUB_XNA overview
WP7 HUB_XNA overviewWP7 HUB_XNA overview
WP7 HUB_XNA overview
 
WP7 HUB_XNA
WP7 HUB_XNAWP7 HUB_XNA
WP7 HUB_XNA
 
Systematic analysis of GWAP
Systematic analysis of GWAPSystematic analysis of GWAP
Systematic analysis of GWAP
 
Let's make a game unity
Let's make a game   unityLet's make a game   unity
Let's make a game unity
 
3d game engine
3d game engine3d game engine
3d game engine
 
Future warfare
Future warfareFuture warfare
Future warfare
 
Academy PRO: Unity 3D. Scripting
Academy PRO: Unity 3D. ScriptingAcademy PRO: Unity 3D. Scripting
Academy PRO: Unity 3D. Scripting
 
Programmers guide
Programmers guideProgrammers guide
Programmers guide
 
Gamemaker
GamemakerGamemaker
Gamemaker
 
Green My Place Game7 Switch Search
Green My Place Game7 Switch SearchGreen My Place Game7 Switch Search
Green My Place Game7 Switch Search
 
Game development with Cocos2d-x Engine
Game development with Cocos2d-x EngineGame development with Cocos2d-x Engine
Game development with Cocos2d-x Engine
 
38199728 multi-player-tutorial
38199728 multi-player-tutorial38199728 multi-player-tutorial
38199728 multi-player-tutorial
 
Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8
 
The purpose and functions of components of game engines
The purpose and functions of components of game enginesThe purpose and functions of components of game engines
The purpose and functions of components of game engines
 
Lock And Key Initial Design Document
Lock And Key Initial Design DocumentLock And Key Initial Design Document
Lock And Key Initial Design Document
 
Getting started with Unity3D and Oculus Rift
Getting started with Unity3D and Oculus RiftGetting started with Unity3D and Oculus Rift
Getting started with Unity3D and Oculus Rift
 

Similar to Lecture 2: C# Programming for VR application in Unity

Unity workshop
Unity workshopUnity workshop
Unity workshop
fsxflyer789Productio
 
Easy coding a multi device game with FireMonkey
Easy coding a multi device game with FireMonkeyEasy coding a multi device game with FireMonkey
Easy coding a multi device game with FireMonkey
pprem
 
Chapter i c#(console application and programming)
Chapter i c#(console application and programming)Chapter i c#(console application and programming)
Chapter i c#(console application and programming)
Chhom Karath
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
Wingston
 
2-Functions.pdf
2-Functions.pdf2-Functions.pdf
2-Functions.pdf
YekoyeTigabuYeko
 
Mutation testing with PIT
Mutation testing with PITMutation testing with PIT
Mutation testing with PIT
Rafał Leszko
 
Game Development Session - 3 | Introduction to Unity
Game Development Session - 3 | Introduction to  UnityGame Development Session - 3 | Introduction to  Unity
Game Development Session - 3 | Introduction to Unity
Koderunners
 
ma project
ma projectma project
ma projectAisu
 
Game programming workshop
Game programming workshopGame programming workshop
Game programming workshopnarigadu
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
ExcellenceAcadmy
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
ExcellenceAcadmy
 
Python programming workshop session 2
Python programming workshop session 2Python programming workshop session 2
Python programming workshop session 2
Abdul Haseeb
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
Amr Alaa El Deen
 
Types of Gaming Program
Types of Gaming ProgramTypes of Gaming Program
Types of Gaming Program
AbdullahWakeel1
 
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSides Delhi
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
Sang Don Kim
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
Fabio506452
 
Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)
Thinkful
 
Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)
Daniel Friedman
 

Similar to Lecture 2: C# Programming for VR application in Unity (20)

Pong
PongPong
Pong
 
Unity workshop
Unity workshopUnity workshop
Unity workshop
 
Easy coding a multi device game with FireMonkey
Easy coding a multi device game with FireMonkeyEasy coding a multi device game with FireMonkey
Easy coding a multi device game with FireMonkey
 
Chapter i c#(console application and programming)
Chapter i c#(console application and programming)Chapter i c#(console application and programming)
Chapter i c#(console application and programming)
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
 
2-Functions.pdf
2-Functions.pdf2-Functions.pdf
2-Functions.pdf
 
Mutation testing with PIT
Mutation testing with PITMutation testing with PIT
Mutation testing with PIT
 
Game Development Session - 3 | Introduction to Unity
Game Development Session - 3 | Introduction to  UnityGame Development Session - 3 | Introduction to  Unity
Game Development Session - 3 | Introduction to Unity
 
ma project
ma projectma project
ma project
 
Game programming workshop
Game programming workshopGame programming workshop
Game programming workshop
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
 
Python programming workshop session 2
Python programming workshop session 2Python programming workshop session 2
Python programming workshop session 2
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
 
Types of Gaming Program
Types of Gaming ProgramTypes of Gaming Program
Types of Gaming Program
 
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOS
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 
Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)
 
Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)
 

More from Kobkrit Viriyayudhakorn

Thai E-Voting System
Thai E-Voting System Thai E-Voting System
Thai E-Voting System
Kobkrit Viriyayudhakorn
 
Thai National ID Card OCR
Thai National ID Card OCRThai National ID Card OCR
Thai National ID Card OCR
Kobkrit Viriyayudhakorn
 
Chochae Robot - Thai voice communication extension pack for Service Robot
Chochae Robot - Thai voice communication extension pack for Service RobotChochae Robot - Thai voice communication extension pack for Service Robot
Chochae Robot - Thai voice communication extension pack for Service Robot
Kobkrit Viriyayudhakorn
 
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
Kobkrit Viriyayudhakorn
 
Thai Text processing by Transfer Learning using Transformer (Bert)
Thai Text processing by Transfer Learning using Transformer (Bert)Thai Text processing by Transfer Learning using Transformer (Bert)
Thai Text processing by Transfer Learning using Transformer (Bert)
Kobkrit Viriyayudhakorn
 
How Emoticon Affects Chatbot Users
How Emoticon Affects Chatbot UsersHow Emoticon Affects Chatbot Users
How Emoticon Affects Chatbot Users
Kobkrit Viriyayudhakorn
 
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
Kobkrit Viriyayudhakorn
 
Check Raka Chatbot Pitching Presentation
Check Raka Chatbot Pitching PresentationCheck Raka Chatbot Pitching Presentation
Check Raka Chatbot Pitching Presentation
Kobkrit Viriyayudhakorn
 
[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)
[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)
[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)
Kobkrit Viriyayudhakorn
 
[Lecture 4] AI and Deep Learning: Neural Network (Theory)
[Lecture 4] AI and Deep Learning: Neural Network (Theory)[Lecture 4] AI and Deep Learning: Neural Network (Theory)
[Lecture 4] AI and Deep Learning: Neural Network (Theory)
Kobkrit Viriyayudhakorn
 
[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)
[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)
[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)
Kobkrit Viriyayudhakorn
 
Lecture 12: React-Native Firebase Authentication
Lecture 12: React-Native Firebase AuthenticationLecture 12: React-Native Firebase Authentication
Lecture 12: React-Native Firebase Authentication
Kobkrit Viriyayudhakorn
 
Thai Word Embedding with Tensorflow
Thai Word Embedding with Tensorflow Thai Word Embedding with Tensorflow
Thai Word Embedding with Tensorflow
Kobkrit Viriyayudhakorn
 
Lecture 3 - ES6 Script Advanced for React-Native
Lecture 3 - ES6 Script Advanced for React-NativeLecture 3 - ES6 Script Advanced for React-Native
Lecture 3 - ES6 Script Advanced for React-Native
Kobkrit Viriyayudhakorn
 
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
Kobkrit Viriyayudhakorn
 
Startup Pitching and Mobile App Startup
Startup Pitching and Mobile App StartupStartup Pitching and Mobile App Startup
Startup Pitching and Mobile App Startup
Kobkrit Viriyayudhakorn
 
React Native Firebase Realtime Database + Authentication
React Native Firebase Realtime Database + AuthenticationReact Native Firebase Realtime Database + Authentication
React Native Firebase Realtime Database + Authentication
Kobkrit Viriyayudhakorn
 
React Native Firebase
React Native FirebaseReact Native Firebase
React Native Firebase
Kobkrit Viriyayudhakorn
 
React-Native Lecture 11: In App Storage
React-Native Lecture 11: In App StorageReact-Native Lecture 11: In App Storage
React-Native Lecture 11: In App Storage
Kobkrit Viriyayudhakorn
 
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
Kobkrit Viriyayudhakorn
 

More from Kobkrit Viriyayudhakorn (20)

Thai E-Voting System
Thai E-Voting System Thai E-Voting System
Thai E-Voting System
 
Thai National ID Card OCR
Thai National ID Card OCRThai National ID Card OCR
Thai National ID Card OCR
 
Chochae Robot - Thai voice communication extension pack for Service Robot
Chochae Robot - Thai voice communication extension pack for Service RobotChochae Robot - Thai voice communication extension pack for Service Robot
Chochae Robot - Thai voice communication extension pack for Service Robot
 
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
 
Thai Text processing by Transfer Learning using Transformer (Bert)
Thai Text processing by Transfer Learning using Transformer (Bert)Thai Text processing by Transfer Learning using Transformer (Bert)
Thai Text processing by Transfer Learning using Transformer (Bert)
 
How Emoticon Affects Chatbot Users
How Emoticon Affects Chatbot UsersHow Emoticon Affects Chatbot Users
How Emoticon Affects Chatbot Users
 
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
 
Check Raka Chatbot Pitching Presentation
Check Raka Chatbot Pitching PresentationCheck Raka Chatbot Pitching Presentation
Check Raka Chatbot Pitching Presentation
 
[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)
[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)
[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)
 
[Lecture 4] AI and Deep Learning: Neural Network (Theory)
[Lecture 4] AI and Deep Learning: Neural Network (Theory)[Lecture 4] AI and Deep Learning: Neural Network (Theory)
[Lecture 4] AI and Deep Learning: Neural Network (Theory)
 
[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)
[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)
[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)
 
Lecture 12: React-Native Firebase Authentication
Lecture 12: React-Native Firebase AuthenticationLecture 12: React-Native Firebase Authentication
Lecture 12: React-Native Firebase Authentication
 
Thai Word Embedding with Tensorflow
Thai Word Embedding with Tensorflow Thai Word Embedding with Tensorflow
Thai Word Embedding with Tensorflow
 
Lecture 3 - ES6 Script Advanced for React-Native
Lecture 3 - ES6 Script Advanced for React-NativeLecture 3 - ES6 Script Advanced for React-Native
Lecture 3 - ES6 Script Advanced for React-Native
 
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
 
Startup Pitching and Mobile App Startup
Startup Pitching and Mobile App StartupStartup Pitching and Mobile App Startup
Startup Pitching and Mobile App Startup
 
React Native Firebase Realtime Database + Authentication
React Native Firebase Realtime Database + AuthenticationReact Native Firebase Realtime Database + Authentication
React Native Firebase Realtime Database + Authentication
 
React Native Firebase
React Native FirebaseReact Native Firebase
React Native Firebase
 
React-Native Lecture 11: In App Storage
React-Native Lecture 11: In App StorageReact-Native Lecture 11: In App Storage
React-Native Lecture 11: In App Storage
 
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
 

Recently uploaded

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

Lecture 2: C# Programming for VR application in Unity

  • 1. Lecture 2: C# Programming 
 by Making Gold Miner Game Dr. Kobkrit Viriyayudhakorn iApp Technology Limited kobkrit@iapp.co.th ITS488 (Digital Content Creation with Unity - Game and VR Programming)
  • 2. Troubleshooting • Confuse? Read a manual at https://docs.unity3d.com/2017.1/ Documentation/Manual/UnityManual.html • Get any problem? Google it: "DOING ANYTHING in unity"

  • 3. Review: Writing Code in Unity Right click at Project Window Name it as "ConsolePrinter"
  • 4. Start writing a code • Double Click at the ConsolePrinter.cs • The MonoDevelop-Unity IDE will be show up and you can make the first program.
  • 6. Printing a Text Save and Go back to Unity
  • 7. Create a New Game Object Right click Select Rename + Enter Inspect Window
 on the right.
  • 8. Attaching Script to A Game Object 1. Drag the ConsolePrinter script and drop onto ConsolePrinterGO in Hierarchy Window
 2. Or Drag onto 
 Inspector Window
  • 9. Start Running • Click on Run Button • Switch to Console Window, you will see "Hello World!" text.

  • 12. Variable #2: int & float & string Output Console
  • 13. Variable #3: int & float oper. Output Console
  • 14. Variable #4: string & bool oper. Output Console
  • 15. Type Represents Range Default Value bool Boolean value True or False FALSE byte 8-bit unsigned integer 0 to 255 0 char 16-bit Unicode character U +0000 to U +ffff '0’ decimal 128-bit precise decimal values with 28-29 significant digits (-7.9 x 1028 to 7.9 x 1028 ) / 100 to 28 0.0M double 64-bit double-precision floating point type (+/-)5.0 x 10-324 to (+/-)1.7 x 10308 0.0D float 32-bit single-precision floating point type -3.4 x 1038 to + 3.4 x 1038 0.0F int 32-bit signed integer type -2,147,483,648 to 2,147,483,647 0 long 64-bit signed integer type -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 0L sbyte 8-bit signed integer type -128 to 127 0 short 16-bit signed integer type -32,768 to 32,767 0 uint 32-bit unsigned integer type 0 to 4,294,967,295 0 ulong 64-bit unsigned integer type 0 to 18,446,744,073,709,551,615 0 ushort 16-bit unsigned integer type 0 to 65,535 0
  • 17. Game Planning • You are a gold miner and you want to find a gold pit. • You can move up, down, left, and right. • Movement is a fixed distance. • After each turn, your distance from the gold pit is displayed. • You win when you get the gold pit. • Your score is how many turns it took.
  • 18. Rough Pseudo Code • Set Start Location • Calculate distance from Gold pit. • Print the distance • Read player’s move • Update location from the Gold pit. • Repeat.
  • 19. Start Writing a Game Logic Output Console
  • 20. If we change loc = 10.3 Output Console
  • 21. Rough Pseudo Code • Set Start Location • Calculate distance from Gold pit. • Print the distance • Read player’s move • Update location from the Gold pit. • Repeat.
  • 23. Reading User Input Output Console 
 (After press left arrow couple times) Make sure you select the Game tab
 Before pressing the left key. ->
  • 24. Adding more Keydown Output Console 
 (After press left+right arrow couple times) * Make sure you select the Game tab
 Before pressing the left key.
  • 27. Make it class variable Scope of loc Move the variable declaration from within "Start()" Method to within "GoldMiner" class.
 (Outer the "Start()" method) Output Console
  • 28. Class variable assignment • Can not be the product from the computation. • Can be a constant or not assignment at all. • You can re-assign the class variable in any function body.
  • 29. Do Distance Calculation when a key is pressed. Output Console Now it is playable!
  • 30. Too much duplicate code! • Using a method / function for repeatedly run code. • Make code much shorter. Easier to manage the code structure. Function!
  • 31. • Return nothing, just print the message out. • Use "void" return type. • Call it when you want to re-calculate the distance. • Call it when you want to print out the distance result. Create calculateDistance Function
  • 32. Completed Game for 1D world. Keep pressing right arrow

  • 33. Programming C# for 2D world
  • 37. Finding Distance of Two Vectors Gold
 Miner (0,0) Gold
 Pit - Gold Miner + Gold Pit
  • 38. Objects and Class Class Car Class = Template Object = Product new
  • 40. Converting from 1d to 2d • Using the Vector2 instead of float (Don’t forget the new keyword) • Update distance to be pathToGoldPit Vector2 • Compute the distance by using Vector2 magnitude property. • Remove all non make-sense code (written for 1d world).
  • 41. Converting from 1d to 2d the magnitude of vector = the length of the vector
  • 42. Converting from 1d to 2d Since we could not compare less than and greater than in the Vector2 class, the code in the block need to be removed, otherwise, the complication errors.
  • 43. Update the location in Vector2 X Y
  • 44. Testing Haha! We forgot Up and Down button. We can not win!
  • 45. Public variables Inspector Panel All public variable will be debuggable in the Inspector Panel. You can change the value and 
 see the change in real time!
  • 46. Exercise I • Implement Up and Down button, so the player can completed the game. • Starting code is located at https://github.com/kobkrit/vr2017class/blob/ master/exercise1.cs
  • 47. Glossary 1 Name Meaning Example Value Numbers, text, etc. “Hello world”, 3.14f, 1 Type The “shape” of the value. int, float, string Variable The correctly typed box for the values. int anInteger; Statement A command to the computer. print("hello") Expression A command that evaluates to a value. homeLocation - location "Distance:" + distance
  • 48. Glossary 2 Name Meaning Example Method A factory which something to input to get output. Input.GetKeyDown(...) Arguments The inputs to a method KeyCode.RightArrow Return value The output of a method if(Input.GetKeyDown(...)) Operation Like a method but with an operator rather than a name. Often ‘infix’. 1 + 2
  • 49. Glossary 3 Name Meaning Example Object A collection of variables with values and methods that act on those variables. The actual house. Class The blueprint of the variables and methods. An architect's drawing of a house. Instantiation The process of making an object from a class. new Vector2(2.0f, 3.0f) Instance Same as an object. Often used to say “an instance of a class X”. The actual house according to drawings X.
  • 50. Homework • Can we print out the location into the console? • If we have multiple gold pits? • If we have traps? • When an user fells to the traps, GAME OVER!