Skip to content

Instantly share code, notes, and snippets.

@vonnenaut
Last active October 24, 2022 15:53
Show Gist options
  • Select an option

  • Save vonnenaut/908d38ba0e2bd108294c29428c4e1857 to your computer and use it in GitHub Desktop.

Select an option

Save vonnenaut/908d38ba0e2bd108294c29428c4e1857 to your computer and use it in GitHub Desktop.
Unity

Unity

Setup

Ubuntu

How to Install a specific archived version of the Unity Editor on Ubuntu 20.04:

  1. Go to archives and copy link from Unity Hub install green button
  2. Go to CLI and CD to folder where Unity Hub binary is located, then paste the link after a call to execute Unity Hub binary:

$DIR/UnityHub.AppImage unityhub://2018.3.0f2/6e9a27477296

Unity Hub should start downloading the specified verison of the editor

 


(Unit) Testing

  1. Add Test Runner tab via General --> Test Runner

  2. Add test .cs scripts to Test subfolder

and be mindful of static editor tests vs tests while running the game

 


UI Basics

  • reset view via Window --> Layouts --> Default
    • click object in Hierarchy to highlight it and press f to focus on it in the window
  • press alt + left-mouse to rotate around the object
  • q, w, e, r, t to choose between tools at top-left (hand, move, rotate, scale and rect)

Framerate Independence

Simple Example of Framerate Independence
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Mover : MonoBehaviour
{
    [SerializeField] float moveSpeed = 4.8f;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float xValue = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
        float zValue = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;

        transform.Translate(xValue,0,zValue);
    }
}

Cinemachine Camera Controller

https://docs.unity3d.com/Packages/[email protected]/manual/index.html

Follow Camera Setup

install via Window --> Package Manager --> Packages: In Project --> Packages: Unity Registry (change drop-down) --> search 'Cinemachine' and press Install

  • creates new 'Cinemachine' Menu item

click on 'Main Camera' --> on right, click 'Add component' --> search 'Cinemachine' to see all components that can be added to Main Camera --> click 'CinemachineBrain' and add it

  • Then, click on 'Cinemachine' at top menu and 'Create Virtual Camera'

  • rename to 'Virtual Follow Camera'

  • click the new camera, change Body type to 'Framing Transposer'

  • 'Look at' will behave like a security camera, staying in place but pointing at object

  • 'Follow' will follow object around like a perspective

Collisions

  1. ensure enabled box collider
  2. add rigidbody component to object (lower-right)
# Unity
## UI Basics
- reset view via `Window --> Layouts --> Default`
- - click object in `Hierarchy` to highlight it and press `f` to focus on it in the window
- press `alt + left-mouse` to rotate around the object
- `q, w, e, r, t` to choose between tools at top-left (hand, move, rotate, scale and rect)
### Framerate Independence
<details>
<summary>Simple Example of Framerate Independence</summary>
```c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mover : MonoBehaviour
{
[SerializeField] float moveSpeed = 4.8f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float xValue = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
float zValue = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
transform.Translate(xValue,0,zValue);
}
}
```
</details>
### Cinemachine Camera Controller
https://docs.unity3d.com/Packages/[email protected]/manual/index.html
#### Follow Camera Setup
**install** via `Window --> Package Manager --> Packages: In Project --> Packages: Unity Registry (change drop-down) --> search 'Cinemachine' and press Install`
- creates new 'Cinemachine' Menu item
click on 'Main Camera' --> on right, click 'Add component' --> search 'Cinemachine' to see all components that can be added to Main Camera --> **click 'CinemachineBrain' and add it**
- Then, click on 'Cinemachine' at top menu and 'Create Virtual Camera'
- rename to 'Virtual Follow Camera'
- click the new camera, change Body type to 'Framing Transposer'
- 'Look at' will behave like a security camera, staying in place but pointing at object
- 'Follow' will follow object around like a perspective
### Collisions
1. ensure enabled box collider
2. add rigidbody component to object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment