Skip to content

Instantly share code, notes, and snippets.

@nkrkt
nkrkt / Singleton.cs
Created January 28, 2020 03:21
base class for singletons, which inherits from monobehaviour (Unity)
using UnityEngine;
/*
* Base class for singletons. Inherit from this class to create a monobehavior singleton.
* This is useful for manager classes, main game logic, or any 'static' class that you want handy access to or need monobehavior functionality.
*
* Usage:
* public class SomeManagerClass : Singleton<SomeManagerClass>
* {
* public bool someBool;
* }
@nkrkt
nkrkt / AudioEffectManager.cs
Last active January 28, 2020 03:27
A script to manage loading and playing audio clips from the resources folder in Unity. Note that this requires the Singleton script I posted as another gist.
using UnityEngine;
using UnityEngine.Audio;
using System.Collections;
using System.Collections.Generic;
/*
* Singleton class for playing audio files on the fly from code
* USAGE:
* --------------------------------------
* put audio you want to play in Assets/Resources/Sound/
@nkrkt
nkrkt / StateMachine.cs
Created January 28, 2020 03:14
A simple implementation of a state machine for Unity C#
using UnityEngine;
namespace FiniteStateMachine
{
class StateMachine : MonoBehaviour
{
public State currentState;
public bool TransitionInFixedUpdate = false;