Fix typos

This commit is contained in:
Marcello 2021-09-20 19:35:32 +02:00
parent 76550dfa3c
commit 5c0799df7f
118 changed files with 1150 additions and 1602 deletions

View file

@ -2,14 +2,14 @@
## Rigidbody Component
Enables physycs on the game objects.
Enables physics on the game objects.
Rigidbodies collide with other objects instead of going through them.
Avoid obejct rotation on colisions:
Avoid object rotation on collisions:
1. Assign `Rigidbody` component to object
2. Enable Freeze Rotaion in Rigidbody > Constraints
2. Enable Freeze Rotation in Rigidbody > Constraints
```cs
using UnityEngine;
@ -21,19 +21,19 @@ public class GameObject : MonoBehaviour {
void Start()
{
rigidbody = GetComponenet<Rigidbody>(); // get rigidbody reference
rigidbody = GetComponent<Rigidbody>(); // get rigidbody reference
}
void Update()
{
}
// FixedUpdate is calles every x seconds (not influenced by FPS instability)
// used for physics calculations which sould be FPS independant
// FixedUpdate is calls every x seconds (not influenced by FPS instability)
// used for physics calculations which should be FPS independent
void FixedUpdate()
{
Time.fixedDeltaTime; // fixed amount of time
Time.timeDelta; // if called inside FIxedUpadate() behaves like fixedDeltaTime
Time.timeDelta; // if called inside FIxedUpdate() behaves like fixedDeltaTime
}
}
@ -44,8 +44,8 @@ public class GameObject : MonoBehaviour {
Enable `Is Trigger` to register the collision but avoid blocking the movement of the objects.
The trigger can generate a event to signal the contact with the object.
One of the collidng GameObjects *must have* the `Rigidbody` component and the other `Is Trigger` enabled.
To detect the collison but avoid computing the physycs `Is Kinematic` must be enabled in the `Rigidbody` component.
One of the colliding GameObjects *must have* the `Rigidbody` component and the other `Is Trigger` enabled.
To detect the collision but avoid computing the physics `Is Kinematic` must be enabled in the `Rigidbody` component.
```cs
using UnityEngine;
@ -57,21 +57,21 @@ public class GameObject : MonoBehaviour {
void Start()
{
rigidbody = GetComponenet<Rigidbody>(); // get rigidbody reference
rigidbody = GetComponent<Rigidbody>(); // get rigidbody reference
}
// FixedUpdate is calles every x seconds (not influenced by FPS instability)
// used for physics calculations which sould be FPS independant
// FixedUpdate is calls every x seconds (not influenced by FPS instability)
// used for physics calculations which should be FPS independent
void FixedUpdate()
{
Time.fixedDeltaTime; // fixed amount of time
Time.timeDelta; // if called inside FIxedUpadate() behaves like fixedDeltaTime
Time.timeDelta; // if called inside FixedUpdate() behaves like fixedDeltaTime
}
// called on box collision.
void OnTriggerEnter(Collider triggerCollider) {
// detect a collison with a perticular GameObject(must have a TAG)
// detect a collision with a particular GameObject(must have a TAG)
if (triggerCollider.tag = "tag") {
Destroy(triggerCollider.gameObject); // destroy tagged item on collision
//or

View file

@ -2,7 +2,7 @@
[Coroutines - Unity manual](https://docs.unity3d.com/Manual/Coroutines.html)
When you call a function, it runs to completion before returning. This effectively means that any action taking place in a function must happen *within a single frame update*; a function call cant be used to contain a procedural animation or a sequence of events over time.
When you call a function, it runs to completion before returning. This effectively means that any action taking place in a function must happen *within a single frame update*; a function call can't be used to contain a procedural animation or a sequence of events over time.
A coroutine is like a function that has the ability to pause execution and return control to Unity but then to continue where it left off on the following frame.
@ -22,7 +22,7 @@ IEnumerator coroutine()
// or
yeld return StartCoroutine(coroutine()); // wait for anothe coroitine to finish before starting
yeld return StartCoroutine(coroutine()); // wait for another coroutine to finish before starting
}
StartCoroutine(coroutine()); // start the coroutine

View file

@ -4,7 +4,7 @@ The Input Manager uses the following types of controls:
- **Key** refers to any key on a physical keyboard, such as `W`, `Shift`, or the `space bar`.
- **Button** refers to any button on a physical controller (for example, gamepads), such as the `X` button on an Xbox One controller.
- A **virtual axis** (plural: axes) is mapped to a **control**, such as a button or a key. When the user activates the control, the axis receives a value in the range of `[1..1]`.
- A **virtual axis** (plural: axes) is mapped to a **control**, such as a button or a key. When the user activates the control, the axis receives a value in the range of `[-1..1]`.
## Virtual axes
@ -30,8 +30,8 @@ The Input Manager uses the following types of controls:
Axis values can be:
- Between `1` and `1` for joystick and keyboard input. The neutral position for these axes is `0`. Some types of controls, such as buttons on a keyboard, arent sensitive to input intensity, so they cant produce values other than `1`, `0`, or `1`.
- Mouse delta (how much the mouse has moved during the last frame) for mouse input. The values for mouse input axes can be larger than `1` or smaller than `1` when the user moves the mouse quickly.
- Between `-1` and `1` for joystick and keyboard input. The neutral position for these axes is `0`. Some types of controls, such as buttons on a keyboard, aren't sensitive to input intensity, so they can't produce values other than `-1`, `0`, or `1`.
- Mouse delta (how much the mouse has moved during the last frame) for mouse input. The values for mouse input axes can be larger than `1` or smaller than `-1` when the user moves the mouse quickly.
```cs
//Define the speed at which the object moves.

View file

@ -1,8 +1,8 @@
# Prefabs
Prefabs are a blueprint for GameObcets and any change made to the prefab is inherited by all it's instances.
Prefabs are a blueprint for GameObjects and any change made to the prefab is inherited by all it's instances.
## Script Instantation
## Script Instantiation
```cs

View file

@ -1,6 +1,6 @@
# Raycasting Notes
A raycast is conceptually like a laser beam that is fired from a point in space along a particular directuin. Any object making contact with the beam can be detected and reported.
A raycast is conceptually like a laser beam that is fired from a point in space along a particular direction. Any object making contact with the beam can be detected and reported.
## 3D Raycasting
@ -16,13 +16,13 @@ void Update()
hitInfo.transform // transform og the hit object
hitInfo.collider.gameObject // reference to the object hit by the ray
hitInfo.collider.gameObject // reference to the object hit by the ray
hitInfo.normal // normal bector og the hit surface
hitInfo.normal // normal vector og the hit surface
hitInfo.point // actual point of collision
// static method, object must haave a collider dot the collision to happen, returns a BOOL
// static method, object must have a collider dot the collision to happen, returns a BOOL
Physics.Raycast(ray, out hitInfo); // update hitInfo based on ray collisions
Physics.Raycast(ray, out hitInfo, float maxRayDistance); // limit the ray length
Physics.Raycast(ray, out hitInfo, Mask mask); // specify with which layers the ray can interact, layer must be allpied to object's mask
Physics.Raycast(ray, out hitInfo, Mask mask); // specify with which layers the ray can interact, layer must be applied to object's mask
Physics.Raycast(ray, out hitInfo, Mask mask, QueryTriggerInteraction.Ignore); // ignore collision if "is trigger" is enabled on other objects
// detect a collision
@ -30,12 +30,12 @@ void Update()
{
//collision happened
// draw the ray ingame for debuggng
// draw the ray in game for debugging
Debug.DrawLine(ray.origin, hitInfo.point, Color.red); // draw red line if collision happens
}
else
{
Debug.DrawLine(ray.origin, ray.origin + ray.direction * 100, Color.blue); // draw blue line if collision happens, arrival point is 100 units from the origin sinche the ray goes to infinity
Debug.DrawLine(ray.origin, ray.origin + ray.direction * 100, Color.blue); // draw blue line if collision happens, arrival point is 100 units from the origin since the ray goes to infinity
}
}
```
@ -47,8 +47,8 @@ public Camera gameCamera;
void Update()
{
// ray goint ftom cametra through a screen point
Ray ray = gameCamera.ScreenPointToRay(Input.mousePosition); // Input.mousePosition is the postion of the mouse in pixels (screen points)
// ray going from camera through a screen point
Ray ray = gameCamera.ScreenPointToRay(Input.mousePosition); // Input.mousePosition is the position of the mouse in pixels (screen points)
RaycastHit hitInfo; // place pointed by the mouse
Physics.Raycast(ray, out hitInfo) // update pointed position
@ -61,12 +61,12 @@ void Update()
void Start()
{
Physisc2D.queriesStartColliders = false; // avoid collision with collider of the ray generator gameObject
Physics2D.queriesStartColliders = false; // avoid collision with collider of the ray generator gameObject
}
void Update()
{
// returns a RaycastHit2D, needs an origin and direction separatedly
// returns a RaycastHit2D, needs an origin and direction separately
Raycast2D hitInfo = Physics2D.Raycast(Vector2 origin, Vector2 direction);
Raycast2D hitInfo = Physics2D.Raycast(Vector2 origin, Vector2 direction, float maxRayDistance);
Raycast2D hitInfo = Physics2D.Raycast(Vector2 origin, Vector2 direction, float maxRayDistance);

View file

@ -24,25 +24,25 @@ public class ClassName : MonoBehaviour {
Time.deltaTime; // time since last frame
}
// FixedUpdate is calles every x seconds (not influenced by FPS instability)
// used for physics calculations which sould be FPS independant
// FixedUpdate is calls every x seconds (not influenced by FPS instability)
// used for physics calculations which should be FPS independent
void FixedUpdate()
{
Time.fixedDeltaTime; // fixed amount of time
Time.timeDelta; // if called inside FIxedUpadate() behaves like fixedDeltaTime
Time.timeDelta; // if called inside FIxedUpdate() behaves like fixedDeltaTime
}
}
```
### Script comunication
### Script communication
Referencing data in a sctipt from another.
Referencing data in a script from another.
```cs
//example of a script to be referenced in another
Using System;
public class Player : MonoBheaviour {
public class Player : MonoBehaviour {
public float health = 10;
public event Action OnPlayerDeath; //event of type Action, needs using System
@ -55,7 +55,7 @@ public class Player : MonoBheaviour {
if (health <= 0) {
if (OnPlayerDeath != null) {
OnPleyerDeath(); // invoke Action (if no subscribers event will be NULL, can cause errors)
OnPlayerDeath(); // invoke Action (if no subscribers event will be NULL, can cause errors)
}
Destroy(GameObject); // needs to be notified
@ -68,7 +68,7 @@ public class Player : MonoBheaviour {
// example of script needing a reference to another
public class GameUI : MonoBehaviour {
Player player; //instance of referenced GameObject to be founf by its type
Player player; //instance of referenced GameObject to be found by its type
void Start(){
GameObject playerObj = GameObject.Find("Player"); //reference to game object
@ -77,7 +77,7 @@ public class GameUI : MonoBehaviour {
player = FindObjectOfType<Player>(); // get reference to an object
// on event invocation all subscribet methods will be called
// on event invocation all subscriber methods will be called
player.OnPlayerDeath += GameOver; // subscribe method to event
}
@ -85,7 +85,7 @@ public class GameUI : MonoBehaviour {
DrawHealthBar(plyer.health); // call method passing data of player GameObject
}
void DrawHealthbar(float playerHealth) {
void DrawHealthBar(float playerHealth) {
// implementation
}
@ -100,9 +100,9 @@ public class GameUI : MonoBehaviour {
### 2D Screen Measures
Aspect Ratio = `(screen_width [px]) / (screen_height [px])`
Orhograpic Size `[world units]` = `(screen_height [world units] / 2)`
Aspect Ratio * Orhograpic Size = `(screen_width [world units] / 2)`
Screen Width `[world units]` = `(AspectRatio * OrhograpicSize * 2)`
Orthographic Size `[world units]` = `(screen_height [world units] / 2)`
Aspect Ratio * Orthographic Size = `(screen_width [world units] / 2)`
Screen Width `[world units]` = `(AspectRatio * OrthographicSize * 2)`
```cs
screenWidth = Camera.main.aspect * Camera.main.orthographicSize * 2;
@ -123,7 +123,7 @@ public class ScriptableObjectName : ScriptableObject {
### Game Object Serialization
```c#
[SeralizeField] type variable; //access game object from code
[SerializeField] type variable; //access game object from code
```
### Game Object Data Access

View file

@ -1,4 +1,4 @@
# Vector, Tranfrorm, Space
# Vector, Transform, Space
## Vector2, Vector3, Vector4
@ -33,8 +33,8 @@ Vector3.one // Vector3(1, 1, 1)
### Operations
```cs
Vector3(x, y, z) * n = Vecotr3(xn, yn, yz);
Vector3(x, y, z) / n = Vecotr3(x / n, y / n, y / z);
Vector3(x, y, z) * n = Vector3(xn, yn, yz);
Vector3(x, y, z) / n = Vector3(x / n, y / n, y / z);
Vector3(x1, y1, z1) + Vector3(x2, y2, z2) = Vector3(x1 + x2, y1 + y2, z1 + z2);
Vector3(x1, y1, z1) - Vector3(x2, y2, z2) = Vector3(x1 - x2, y1 - y2, z1 - z2);
@ -54,11 +54,11 @@ MovementInFrame = Speed * timeSinceLastFrame
[Transform Docs](https://docs.unity3d.com/ScriptReference/Transform.html)
```cs
// propetries
transfrom.position // Vector3 - global position
transfrom.localPosition // Vector3 - local position
// properties
transform.position // Vector3 - global position
transform.localPosition // Vector3 - local position
transform.rotation // Quaternion - global rotation
transfrom.parent // Transform - parent of the object
transform.parent // Transform - parent of the object
transform.localScale = Vector3; // set object dimensions
@ -67,21 +67,21 @@ transform.Rotate(Vector3 * Time.deltaTime * speed, Space); // set rotation usin
transform.Translate(Vector3 * Time.deltaTime * speed, Space); // set movement in selected space
```
### Local, GLobal & Object Spcace
### Local, GLobal & Object Space
**Local Space**: Applies transformation relative to the *local* coordinate system (`Space.Self`).
**Global Space**: Applies transformation relative to the *world* coordinate system (`Space.World`)
### Parenting
Changing the parent will make position, scale and rotation of the child object retalive to the parent but keep the world space's position, rotation and scale the same.
Changing the parent will make position, scale and rotation of the child object relative to the parent but keep the world space's position, rotation and scale the same.
Setting the parentele by script:
```cs
public class ParentScript : MonoBehaviour {
public Transform childTransform; // reference to the child object transfrom
public Transform childTransform; // reference to the child object transform
childTrandform.parent = transfrom; // when evaluated at runtime sets current object as parent of another
childTransform.parent = transform; // when evaluated at runtime sets current object as parent of another
}
```