Unity

12 min. read

Unity is a cross-platform game engine developed by Unity Technologies, which is primarily used to develop video games and simulations for computers, consoles, and mobile devices.

Unity offers a powerful rendering engine and a comprehensive set of tools and features for creating interactive 3D content, making it a popular choice among game developers.

Unity is a complex system of various modules and packages:

Getting Started with Unity

There are quite a number of “Getting started with Unity” on other sites. We are working on creating our own, please check back soon.

Unity Shortcut Keys

CTRL + P = Play
CTRL + SHIFT + P = Pause
SPACEBAR Maximus panel

Editor Navigation

Right click + WASD = FPS movement

GUI Text

Import the Font you want to use.

Note: Normal Windows Fonts are located under Windows->Fonts

With the Font selected click Menu->Game Object->Create Other->GUI Text

A new GUI text will be created.

GUI works only on X and Y, if you want to place an object in front of another object. Use Z for Order (Higher numbers are on top)

GUI Texture

Import a PNG file to use with the GUI Texture

Select the newly imported file, then click Menu->Game Object->Create Other->GUI Texture

A new GUI texture will be created from the PNG file.
Scale to full screen
UIText and GUITexture uses ViewPort space.

Pixel Inset
x = 0
y = 0
width = 0
height = 0
Scale
x = 1
y = 1

3D Text

Menu->Game Object->Create Other->3D Text

Replace the default font, with the font you wish to use.

The text will most likely be distorted when you the any other Font other than arial.

To fix this:

Select the 3D text, under “Mesh Renderer” replace “font material” with the font material on your imported Font.

Now, it will be blurry:

To fix this:

Change the Font size to a bigger number
Go to 3D text and change the Character size to a smaller number.

Adjust the size till you are happy.

To make the 3D text selectable, add Menu->Component->Physics->Box Collider

Scripts:

Changing textures

guiTexture.texture = newTexture;

GameObject.Find(“levelGUI”).GetComponent(GUITexture).enabled = false;

[ExecuteInEditMode]

public enum RuntimePlatform
{
OSXEditor = 0,
OSXPlayer = 1,
WindowsPlayer = 2,
OSXWebPlayer = 3,
OSXDashboardPlayer = 4,
WindowsWebPlayer = 5,
WiiPlayer = 6,
WindowsEditor = 7,
IPhonePlayer = 8,
PS3 = 9,
XBOX360 = 10,
Android = 11,
NaCl = 12,
LinuxPlayer = 13,
}

C# Scripts:

Script to open doors:

void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.gameObject.tag == “door”)
{
Door(doorOpenSound, true, “dooropen”, currentDoor);
}
}

void Door(AudioClip clip, bool isOpen, String animationName, GameObject theDoor)
{
audio.PlayOneShot(clip);
theDoor.transform.parent.animation.Play(animationName);
}

Ray Casting

RaycastHit hit = new RaycastHit();

if (Physics.Raycast(transform.position, transform.forward, out hit, 5))
{
if (hit.collider.gameObject.tag == “door”)
{
//Do whaterver here
//Play door open sound, animation, etc…
}
}

Triggers

void OnTriggerEnter(Collider collisionInfo)
{
if(collisionInfo.gameObject.tag == “healtBar”)
{
health++;
Destroy(collisionInfo.gameObject);
}
}

Rotation script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
transform.Rotate(new Vector3(0,rotationAmount,0));

Instantiate(object to be created, position of object, rotation of object);


GameObject myPrefab;
Instantiate(myPrefab, transform.position, transform.rotation);

Update()
{
if(Input.GetButtonUp("Fire1"))
{
audio.PlayOneShot(shootSound);
Rigidbody newBullet = Instantiate(objBullet, transform.position, transform.rotation);
newBullet.name = "bullet";
newBullet.rigidbody.velocity = transform.TransformDirection(Vector3(0,0, fltForce));
Physics.IgnoreCollision(transform.root.collider, newBullet.collider, true);
}
}

Remove object after a time

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void Start()
{
Destroy(gameObject, 5);
}

//Look at target
transform.LookAt(target.transform, Vector3.up);

//Slow motion turning
var targetRot = Quaternion.LookRotation(target.transform.position - transform.position, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRot, Time.deltaTime * turnSpeed);

//FixedUpdate should be used instead of Update when dealing with Rigidbody
void FixedUpdate()
{
...
}

Networking

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
public class Connect : MonoBehaviour
{
string remoteIp = "127.0.0.1";
int remotePort = 2500;
int listenPort = 2500;
bool useNAT = false;
string yourIp = "";
string yourPort = "0";

// Use this for initialization
void Start ()
{

}

void OnGUI()
{
if (Network.peerType == NetworkPeerType.Disconnected)
{
if (GUI.Button(new Rect(10, 10, 100, 30), "Connect"))
{
//Network.useNat = useNAT;
Network.Connect(remoteIp, remotePort);
}

if (GUI.Button(new Rect(10, 50, 100, 30), "Start Server"))
{
Network.InitializeServer(4, listenPort, useNAT);

GameObject[] players = FindObjectsOfType(typeof(GameObject)) as GameObject[];
foreach (GameObject obj in players)
{
obj.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}
}

remoteIp = GUI.TextField(new Rect(120, 10, 100, 20), remoteIp);
remotePort = int.Parse(GUI.TextField(new Rect(230, 10, 40, 20), remotePort.ToString()));
}
else
{
string ipAddress = Network.player.ipAddress;
string port = Network.player.port.ToString();

GUI.Label(new Rect(140, 20, 250, 40), string.Format("IP Address {0} {1}", ipAddress, port));

if (GUI.Button(new Rect(10, 10, 100, 50), "Disconnect"))
{
Network.Disconnect(200);
}
}
}

void OnConnectedToServer()
{
GameObject[] players = FindObjectsOfType(typeof(GameObject)) as GameObject[];
foreach (GameObject obj in players)
{
obj.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}
}
}

Application.CaptureScreenshot(“Screenshot.png”);

Adding Grass

Tile Size 15 x 15

Adding Cliff

Tile Size 70 x 70

Adding Trees

Bend Factor: trees to sway in wind, make it 2.
Brush size: 15, painting 15 trees at a time.
Tree Density: 0 Wide spread of trees
Color Variation 0.4
Tree Height/Width: 1.5

Adding Grass (moving)

Brush size: 100
Opacity: 0.05
Target Strength: 0.6

Adding the “sun”

Directional Light:
Flare->Sun
Rotate it to fit Skybox

Adding Sounds

Stereo -> Constant Volume
Mono -> Variable Volume

In game music should be stereo

WAV, MP3, AIFF, OGG

Add audio source to object

Adding Background (Skybox)

Edit->Render Settings

Intersecting Lines

public static MapPoint IntersectionPoint(Polyline firstLine, Polyline secondLine)
{

  MapPoint mp = null;

  ESRI.ArcGIS.Client.Geometry.PointCollection pointsLine1 = firstLine.Paths[0];
  ESRI.ArcGIS.Client.Geometry.PointCollection pointsLine2 = secondLine.Paths[0];
  MapPoint firstLineStartPos = pointsLine1[0];
  MapPoint firstLineEndPos = pointsLine1[1];
  MapPoint secondLineStartPos = pointsLine2[0];
  MapPoint secondLineEndPos = pointsLine2[1];

  double Ua, Ub;



  // Equations to determine whether lines intersect

  Ua = ((secondLineEndPos.X - secondLineStartPos.X) * (firstLineStartPos.Y - secondLineStartPos.Y) - (secondLineEndPos.Y - secondLineStartPos.Y) * (firstLineStartPos.X - secondLineStartPos.X)) /

          ((secondLineEndPos.Y - secondLineStartPos.Y) * (firstLineEndPos.X - firstLineStartPos.X) - (secondLineEndPos.X - secondLineStartPos.X) * (firstLineEndPos.Y - firstLineStartPos.Y));



  Ub = ((firstLineEndPos.X - firstLineStartPos.X) * (firstLineStartPos.Y - secondLineStartPos.Y) - (firstLineEndPos.Y - firstLineStartPos.Y) * (firstLineStartPos.X - secondLineStartPos.X)) /

          ((secondLineEndPos.Y - secondLineStartPos.Y) * (firstLineEndPos.X - firstLineStartPos.X) - (secondLineEndPos.X - secondLineStartPos.X) * (firstLineEndPos.Y - firstLineStartPos.Y));



  if (Ua >= 0.0f && Ua <= 1.0f && Ub >= 0.0f && Ub <= 1.0f)
  {

    double x = firstLineStartPos.X + Ua * (firstLineEndPos.X - firstLineStartPos.X);

    double y = firstLineStartPos.Y + Ua * (firstLineEndPos.Y - firstLineStartPos.Y);

    mp = new MapPoint()
    {
      X = x,
      Y = y
    };
  }
  return mp;
}

Middle Point of a line:

double x = (X1 + X2) / 2;
double y = (Y1 + Y2) / 2;

Lightmapping

Set camera to deferred lighting on PRO
set camera to vertex lit on FREE and mobile
lightmapping does not affect batch.
lightmapping has more textures, so longer load times
use dual lightmaps

Courses

Unity Learn

LinkedIn Learning Unity Courses

2016

2014

Resources

https://blog.unity.com/technology/prefabs-whats-new-2022-2

https://www.youtube.com/channel/UCxBaTADLh3uUKhmP1cQ7ddg/videos

Becoming Better at Unity

  1. linear algebra
  2. probability theory
  3. write your own game engine

Play around with Unity Playground

https://unity3d.com/learn/tutorials/s/unity-playground

https://docs.unity3d.com/Manual/AdvancedDevelopment.html

https://docs.unity3d.com/Manual/class-ScriptableObject.html

https://docs.unity3d.com/ScriptReference/Video.VideoPlayer.html

http://www.what-could-possibly-go-wrong.com/promises-for-game-development/

http://www.what-could-possibly-go-wrong.com/about/

https://en.wikipedia.org/wiki/Behavior_tree_(artificial_intelligence,_robotics_and_control)

https://github.com/Real-Serious-Games/c-sharp-promise

https://catlikecoding.com/unity/tutorials/

https://gist.github.com/luke161

https://thoughtbot.com/blog/avoiding-out-of-memory-crashes-on-mobile

https://thoughtbot.com/blog/an-introduction-to-webgl

https://answers.unity.com/questions/300841/ios-download-files-and-store-to-local-drive.html

https://answers.unity.com/questions/322526/downloading-big-files-on-ios-www-will-give-out-of.html

https://answers.unity.com/questions/970806/download-images-from-url-save-to-device-load-into.html

DOTS

Data-Oriented Technology Stack (DOTS)

Reddit

https://www.reddit.com//r/gameDevClassifieds/wiki/programmers

  1. Complete C# Unity Developer 2D – Learn to Code Making Games (Udemy)
    https://digitaldefynd.com/best-unity-courses/#1_Complete_C_Unity_Developer_2D_Learn_to_Code_Making_Games_Udemy

  2. Complete C# Unity Developer 3D – Learn to Code Making Games (Udemy)
    https://digitaldefynd.com/best-unity-courses/#2_Complete_C_Unity_Developer_3D_Learn_to_Code_Making_Games_Udemy

  3. Unity Game Dev Courses: Fundamentals (Pluralsight)
    https://digitaldefynd.com/best-unity-courses/#3_Unity_Game_Dev_Courses_Fundamentals_Pluralsight

  4. Unity Certification : C# Programming for Unity Game Development (Coursera)
    https://digitaldefynd.com/best-unity-courses/#4_Unity_Certification_C_Programming_for_Unity_Game_Development_Coursera

  5. RPG Core Combat Creator – Learn Intermediate Unity C# Coding
    https://digitaldefynd.com/best-unity-courses/#5_RPG_Core_Combat_Creator_Learn_Intermediate_Unity_C_Coding

  6. The Ultimate Guide to Game Development with Unity (Udemy)
    https://digitaldefynd.com/best-unity-courses/#6_The_Ultimate_Guide_to_Game_Development_with_Unity_Udemy

  7. Complete Blender Creator Course (Udemy)
    https://digitaldefynd.com/best-unity-courses/#7_Complete_Blender_Creator_Course_Udemy

  8. Game Development Certification by Michigan State Univ (Coursera)
    https://digitaldefynd.com/best-unity-courses/#8_Game_Development_Certification_by_Michigan_State_Univ_Coursera

  9. Unity Gameplay Programmer Certification Preparation Course (Coursera)
    https://digitaldefynd.com/best-unity-courses/#9_Unity_Gameplay_Programmer_Certification_Preparation_Course_Coursera

  10. Unity Certified Programmer Exam Preparation Course (Coursera)
    https://digitaldefynd.com/best-unity-courses/#10_Unity_Certified_Programmer_Exam_Preparation_Course_Coursera

Bonus Courses
https://digitaldefynd.com/best-unity-courses/#Bonus_Courses

https://catlikecoding.com/unity/tutorials/

Code Monkey (YouTube)

https://www.youtube.com/channel/UCFK6NCbuCIVzA6Yj1G_ZqCg

https://unitycodemonkey.com/

Unity Learn

https://blogs.unity3d.com/2019/04/29/announcing-unity-learn-a-brand-new-learning-platform/

https://blogs.unity3d.com/2019/06/27/introducing-unity-learn-premium/

freecodecamp

https://www.freecodecamp.org/news/the-ultimate-beginners-guide-to-game-development-in-unity-f9bfe972c2b5/

coursera

Programming for Everybody (Getting Started with Python)

https://www.coursera.org/learn/python

https://www.coursera.org/learn/competitive-strategy

udacity

How to Build a Startup
https://www.udacity.com/course/how-to-build-a-startup--ep245

Startup

http://startupclass.samaltman.com/

udemy

This Is How You Make iPhone Apps - iOS Development Course
https://www.udemy.com/iosdevelopment/learn/lecture/101033#overview

Getting Started with Google Analytics
https://www.udemy.com/getting-started-with-google-analytics/learn/lecture/129503#overview

Unity Learn

https://www.youtube.com/watch?v=qipYRdaNWZY

https://www.youtube.com/watch?v=iEzGn_dX-J4

3D Kit

https://www.youtube.com/watch?v=JpdQqytJiDo

Creator Kit: Puzzle

https://learn.unity.com/project/creator-kit-puzzle

Creator Kit: RPG

https://learn.unity.com/project/creator-kit-rpg

Creator Kit: FPS

https://learn.unity.com/project/creator-kit-fps

https://cgcookie.com/articles/30-things-every-unity-developer-should-know