Skip to content

Instantly share code, notes, and snippets.

@charlieamat
charlieamat / FadingInteractable.cs
Last active October 4, 2021 20:26
[ta-edu-course-survival-game] Chapter 2 — Coroutines (2)
public class FadingInteractable : Interactable
{
[SerializeField] private float duration = 3;
private Renderer _renderer;
public void Interact()
{
StartCoroutine(FadeOut);
}
@charlieamat
charlieamat / Interactable.cs
Last active September 30, 2021 19:00
[ta-edu-course-survival-game] Chapter 2 — Composition vs Inheritance (3)
public class Interactable : MonoBehaviour
{
private InteractionHandler[] _handlers;
public void Awake()
{
_handlers = GetComponents<InteractionHandler>();
}
public void Interact()
@charlieamat
charlieamat / InteractionTests.cs
Last active April 29, 2022 17:58
[ta-edu-course-survival-game] Chapter 4 — PlayMode Tests
using Interactions;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
public class InteractionHandlerTests
{
public class FadeOutTests
{
[UnityTest]
@charlieamat
charlieamat / Instructions_00.md
Last active April 29, 2022 14:22
[ta-edu-course-survival-game] Chapter 4 — EditMode Tests

#TODO

@charlieamat
charlieamat / Combatant.cs
Last active September 30, 2021 19:50
[ta-edu-course-survival-game] Chapter 2 — Script Interactions
public class Combatant : MonoBehaviour
{
public float Health;
public void Damage(int damage)
{
Health = Math.Max(0, Health - damage);
}
}
@charlieamat
charlieamat / Instructions.md
Created September 14, 2021 17:51
[ta-edu-course-survival-game] Chapter 2 — Script Interactions (2)

TODO

@charlieamat
charlieamat / AddToInventory.cs
Last active September 14, 2021 17:54
[ta-edu-course-survival-game] Chapter 2 — Script Interactions (1)
// TODO
@charlieamat
charlieamat / Instructions.md
Created September 14, 2021 15:57
[ta-edu-course-survival-game] Chapter 2—Performance 101 (3)
  1. Click anywhere in the CPU Usage graph
    • We can see that our Update method is taking up a much larger portion of the frame
  2. Change the bottom section of the profiler from timeline to hierarchy view
    • The timeline view is a good visualization, but the hierarchy view provides more actionable information
  3. Order the hierarchy view by “Time ms” and expand “PlayerLoop” all the way down to the script logic
    • By ordering the view by “Time ms” we can narrow down what is taking the CPU so long to execute
    • FindObjectsOfType is taking up some time, so let’s fix that
  4. Switch to Visual Studio
  5. Convert interactables to a private member variable
  6. Initialize interactables in the Start method
@charlieamat
charlieamat / Instructions.md
Last active September 14, 2021 15:54
[ta-edu-course-survival-game] Chapter 2 — Unity Performance 101 (1)
  1. In the top navigation bar, click Window → Analysis → Profiler
  2. (optional) Dock the profiler to the editor
  3. Enable only the CPU Usage and Memory modules
    • Each profiler module provides information about a certain aspect of your game’s performance
    • Performance issues related to your code will appear in the CPU Usage and Memory modules
  4. Run the scene, wait a few seconds, and press the pause button
    • The profiler window is split into two sections
      • The top shows a set of time-based graphs
      • The bottom gives information about the selected frame that’s contextual to the module that is currently in focus
  5. Click on a frame in the CPU Usage graph
@charlieamat
charlieamat / FadingInteractable.cs
Last active October 4, 2021 19:51
[ta-edu-course-survival-game] Chapter 2 — Coroutines (1)
public class FadingInteractable : Interactable
{
[SerializeField] private float duration = 3;
private float _elapsed;
private Renderer _renderer;
private bool _isFading;
public void Interact()
{