Un Flashcards

1
Q

A sprite is

A

An image you imported to your game.
Note:
It is a bitmap, which means pixels and colors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The z-index of game objects is stored under

A

order in layer

Note: Higher numbers are more visible

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The core functions of game object scripts are

A

Start: Initialization game objects (ie RigidBody)
Update: meant for input checks
FixedUpdate: meant for creating physics movements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

To make a variable from the script available in the inspector, type

A

public int myInt = 1;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

c# sheet

A

To write a float, type
0.1f

To write a function, type
public int MyFunc(int number1)
{
    Console.WriteLine("I'm doing something...");
}
Remember to make an explicit declaration when declaring a variable
List-GameObject> allSoldiers = new List();

C# uses angle brackets for Generic Type parameters, meaning when you need to pass in an uninstantiated type class.

To create a class, type
class ClassName
{}

Void functions
Do not return a value

To write a method that doesnt return anything, type
static void MethodName()
{}

The first mandatory method called in any script is
static void Main()
{}

To set the namespace, type
namespace NameSpaceName
{}

To convert a number string into an int, type
int.Parse(“10”)

types can also have
methods. e.g. int.Parse(“10”)

To create a while loop, type
while (varName == true)
{}

To create an if else, type
if (varName == "string")
{}
else if (varName == "string")
{}
else
{}

To make a loop restart back from the beginning, type
continue

To write a try/catch, type
try
{}
catch(ExceptionName)
{}

Variables are only inside
the curly brackets they were declared in

To convert a string to lower case, type
stringVar.ToLower()

The types that can hold decimals are
double, float

To cast a double into an int, type
(int)(10.0)
Note: Casting a number does not round it, it truncates.

“using” statements automatically
call the dispose function on the object after it is used

To initialize a list, type
List = new List()

The difference between a list and an array is
You dont need to set the size of a list, but an array you do.
To make an array: int[]
To make a list: List

To initialize an int array with values, type
List = new List {1,2,3,4,5}
int[] varName = new int[5] {1,2,3,4,5}
or
var varName = new int[5] {1,2,3,4,5}
or
List = new List {1,2,3,4,5}
To initialize a dictionary in c#, type
Dictionary dictName = new Dictionary();
Note: c# does not provide and empty list as the value even if the type is set to list

To add to a dictionary, type
dictName.Add(“key”, “value”)

To get a dictionary value by the key, type
dictName[“key”]

The static modifier is used to
Make a function a class function instead of an instance function

public methods can be called by
anyone

private methods can be called my
only other functions inside the same class

To avoid having to write the namespace, type
using NameSpaceName
note: No ;

Namespaces can be
Nested multiple times

To enter the c# repl, type
csharp

A common compiler for c# is
mono

You can compile c# scripts using mono by typing
mcs ScriptName.cs

To write to the console, type
Debug.Log(“string”);
System.Console.Write(“string”);
System.Console.WriteLine(“string”);

To get input into the console, type
System.Console.ReadLine();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Edits you make while in play mode

A

get deleted when you unplay

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A tileset is

A

an image with small sprites that you can drag to repeat

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A box collider 2d is

A

a box drawn around a game object to give it a barrier that creates collision events
Note: There are other shape colliders

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

To listen for presses on the arrow keys, type

A

Input.GetAxis(“horizontal”)
Note: The value will return 1 if they press right and -1 if they press left

Input.GetAxis(“vertical”)
Note: The value will return 1 if they press up and -1 if they press down

Note: To get these numbers in a more snappy way, type
Input.GetAxisRaw(“…”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The two ways to make an object move are

A

Change the transform.position of the game object

or

Add a force to a RigidBody2D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

You can get premade assets

A

by googling “unity assets 2d”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

To get the current position of a game object in it’s script, type

A

transform.position

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

To trigger animations from a script, type

A

animator = GetComponent()
animator.play(“animation_name”)

This eliminates the need for the visual UI

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A vector is

A

….

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

To add a script to a game object from within a script, type

A

public GameObject myObject; // Or get and existing one

myObject.AddComponent();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

To pan the editor

To zoom in the editor

A

option + mouse drag

control + option + mouse drag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

To detect a click, type

A

if (Input.GetMouseButtonDown(0)) {
Debug.Log(Input.mousePosition);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

To load an asset into a script, you must

A

create a folder directly under the assets fold called “Resources”
Place an asset in there
Load the resource ie
Resources.Load(“AC Player”) as RuntimeAnimatorController

Note: Do not include the “Assets/” or the file extension

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

The difference between GetComponent and AddComponent is

A

GetComponent gets a component that is already added to the object the script is on.
Note: returns null if component is not already added.

AddComponent is used to add a new component to an object.
Note: Calling multiple times will attach multiple instances.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

When you add a new component to a game object, it returns

A

an instance of that component so you can alter its properties after

Rigidbody2D rb = newGameObject.AddComponent();
rb.gravityScale = 0;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

It is easier to access a game objects transform object by

A

using the dot notation than instantiating

newGameObject.transform.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y)

rather than

Transform newGameObjectTransform = newGameObject.transform

Note: Do game objects automatically get a transform component?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

To convert a mouse position to the position in the game, type

A

Vector3 worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

MyGameObject.transform.position = new Vector2(worldPosition.x, worldPosition.y);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

It seems that if you add an animator component to a game object, you do not need to add to the sprite renderer a

A

sprite

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

To make a field in the inspector component show up as a dropdown

A

use an Enum value as the public variable type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

For the game to listen to keyboard events,

A

the mouse must be hovering over the game window

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

To get the direction of an object thats moving, type

A

Vector2 currentDirection = (currentPosition-previousPosition).normalized;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

To give an object some force when it is pushing, use

A

rigidBodyInstance.drag = 1

28
Q

For the box collider, the difference between offset and size is

A

Size is the dimensions of the box, and offset is how far away you want

29
Q

To get a game object instance by its tag, type

A
target = GameObject.FindGameObjectWithTag("Player");
Note: This is a class method, not instance
30
Q

To sort a List, type

A

using System.Linq;

List sortedArray = anArray.OrderBy(item => Vector2.Distance(gameObject.transform.position, item.transform.position)).ToList();

31
Q

The difference between Input.GetMouseButtonDown(0) and Input.GetMouseButton(0) is

A

GetMouseButtonDown returns true for one game loop iteration

GetMouseButton returns true the entire time a click is held

32
Q

To get a touch position from the previous game loop iteration, type

A

touchInstance.deltaPosition

33
Q

OnCollisionEnter2D is called when

A

a game objects collider has begun touching either another rigidbody or collider.

34
Q

a Rigidbody object will automatically be

A

pulled downward by gravity, since a rigidbody gives objects physics.

35
Q

If a Game Object does not need physics, it does not need a

A

RigidBody2D

36
Q

The function animator.SetInteger(“parameterName”, 3) is

A

changing the value of the parameterName in the animation manager that the transitions are listening to.

37
Q

OnCollisionStay2D stops running after a while even though there is still a collision because

A

the Rigidbody2D falls asleep for performance reasons and stops detecting collisions.

38
Q

To have a game object destroy itself, type

A

Destroy(gameObject);

Note: It knows gameObject is a reference to itself.

39
Q

A tag must exist in the list in the game UI before

A

you can add it to a game object in a script

40
Q

HUD stands for

A

heads up display (ie fixed on viewport)

41
Q

Canvas sheet

A

A canvas is
a game object that displays 2D UI elements in screen space (viewport) rather than game space.

To give it a background, you
add a UI -> Panel inside of it

When you add a canvas it gets sized enormously, but in play game mode it just fits to the screen.

A pivot point is effectively the center of an image so when you set its position to a coordinate, that is the point that will go there.

A pivot point is denoted by the light blue circle.

? If your UI element (ie button) uses a Rect Transform component, the way to translate it is to move both the sides of the rectangle. If you only move one side it will just stretch/shrink.

If you add a UI image to your project, it will automatically be inside a canvas. (Sprites go in game space, UI images go in screen space)

If you want to have a basic colored square in your canvas, add an image and it will be a white square.

42
Q

To center a game object in the editor

A

double click it in the left panel hierarchy

43
Q

Anchor point sheet

A

anchor points are like
stakes in the ground with strings connected to one of your blue corner dots, so if your anchor points are on all 4 corners, then any resize vertically or horizontally of screen will pull those corners and stretch your blue corner dots, but if they were clustered together 2 on the left and 2 on the right but the y was 0.5, then stretches vertically wont make them pull on your top and bottom corners.

When you change an anchor point of a UI object,
unity automatically changes its translation in the transform component to accommodate the new anchor points without moving where it was in the UI.

Under the anchors field, the min and max are the separate 4 corners of the anchor points.

min x is bottom left
max x is bottom right
min y is bottom left
max y is top left
(I assume top right is computed)

So if you don’t want any pulling on your corners, you need to put all the anchor points clustered in the center of your object.

For a heath bar (and many multi image objects), all the inner objects should have anchor points set to the corners of the parent object so that they scale in the same proportion to the parent. I supposed unless it might look weird like a photo.

44
Q

Unity counts the x and y starting from the

A

bottom left

45
Q

It seems the components you add to a game object in the UI become

A

available in the script’s environment under their component name lower cased. ie slider, rigidbody2d

46
Q

It is good to use git with Unity because

A

sometimes there is no way to command z a bug

47
Q

?To instantiate a new component into the script, type

A

private ComponentName componentInstance;

48
Q

To to able to get different colors along a gradient based on a value from 0 to 1, type

A

public Gradient gradient;

gradient.Evaluate(0.5f)

49
Q

The proper place for attributes is always in the script on

A

the game object they are most relevant to, since you can make any attribute public and accessible from other scripts or trigger events.

50
Q

In C# to make a float alway positive, type

A

Mathf.Abs(-1.0f)

51
Q

A delegate is a

A

function stored in a variable thats uncalled.

52
Q

An animation manager is

A

where you choose the transition conditions between the animations clips you created.

Animations clips are just multiple sprites separated by a time interval.

To tell the animation manager when to use different animation clips, you
drag a line between 2 animations (called a transition)
This makes it possible for one animation clip to transition to another one.
Create parameters (aka variables) for the transition line to listen to, and add conditions to the transition line so if those variables ever meet the conditions, then the transition will occur.
Then to change those parameters from a script, add an animator component to the script and type (based on the type of parameter you chose)

animator. SetFloat(“ParameterName”, 1)
animator. SetBool(“ParameterName”, true)

Note: Turn off “exit time” if you don’t want the animation to always finish completely before switching.

53
Q

[SerializeField] is used if

A

you want a private variable to be visible in the inspector

54
Q

To create a prefab

A

Create a folder named “Prefabs” inside the Assets folder and drag a game object form the hierarchy into it.

Note: Changing any prefab instances attributes will change it on all other instances of the prefab as well.

55
Q

Tensors

A

A scalars is a
quantities that are fully described by a magnitude

A vector is
an object that has both a magnitude and a direction

A to fully describe a vector you need its
coordinate basis that its being applied to

56
Q

To toggle a game objects visibility, type

A

gameObject.SetActive(false)

57
Q

In c# for strings always use

A

double quotes

58
Q

To make a delay coroutine type

A

Create it and then call it

IEnumerator CoroutineName()
{
    yield return new WaitForSeconds(1f);
    Debug.Log("waited")
}

StartCoroutine(CoroutineName())

59
Q

To get a script from another script, type

A

GameObject myObject = GameObject.FindGameObjectWithTag(“tag”);

myObject.GetComponent().FunctionName(“left”);

Note: I tried creating a variable for the script itself like below but it was null. Its possible that the class needs to be imported before I can use it as a type for the variable declaration.
ScriptName script = canvas.GetComponent();
60
Q

When accessing a public Enum from a different script in and imported script you get it from the

A
class rather than the instance
ScriptName.EnumName
61
Q

To make a scroll list of equally spaced objects, you

A

Add all the list items as children on an object with a Scroll Rect Component and then add a Vertical Layout Group Component to that object too.

62
Q

To instantiate a prefab and set it as a child of an existing game object in the hierarchy, type

A

public GameObject myPrefab;
GameObject content;

    // Start is called before the first frame update
    void Start()
    {
        content = GameObject.FindGameObjectWithTag("Content");
        GameObject go = Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity);
        go.transform.SetParent(content.transform);
    }
63
Q

.gitignore can be stored

A

in any subfolder

64
Q

Package manager sheet

A

To open package manager, go to
window -> package manager

Before package manager, installation was done by
adding a list item to manifest.json

You can also add a package to the manifest.json by
typing in com.unity.localization under “Add package from git URL” in package manager

65
Q

To use localization

A

Basically how localization works is
you create a table with a key per row, and then key value pairs for each language name and translated value.

Create a new folder inside assets folder (can be called Localization for simplicity)

In Edit -> Project Settings -> Localization click create and save the file in the localization folder

To add localization to a text object
Add a Localize String Event Component
Create a table
Add a table reference
Choose the right key for table collection
Create an Update String Function
Drag the text component onto the None and the choose text in the dropdown

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

66
Q

The best way to ID a component for referencing in code is

A

idk, tag?