Skip to content

Instantly share code, notes, and snippets.

View kurtdekker's full-sized avatar

Kurt Dekker kurtdekker

View GitHub Profile
@kurtdekker
kurtdekker / JsonPlayerPrefs.cs
Created October 16, 2021 12:29 — forked from brettmjohnson/JsonPlayerPrefs.cs
A replacement for Unity's PlayerPrefs that stores data in a JSON file.
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
/// <summary>
/// A replacement for Unity's PlayerPrefs that stores data in a JSON file.
/// </summary>
[Serializable]
public class JsonPlayerPrefs
@kurtdekker
kurtdekker / LateFollow.cs
Created November 18, 2021 22:04
Lets one object follow another object using only a positional offset
using UnityEngine;
// @kurtdekker
// Purpose: follows another Transform, maintaining the same offset from it.
// Useful for a detached health bar that follows a rotating ship (for instance).
public class LateFollow : MonoBehaviour
{
public Transform TargetToFollow;
Vector3 Offset;
@kurtdekker
kurtdekker / MakeGridOfSprites.cs
Created December 8, 2021 23:40
Editor script to make a grid of sprites, aka, poor man's tilemap
using UnityEngine;
using UnityEditor;
// @kurtdekker
// cheap and cheerful grid-of-sprites maker
// this is an editor-time application
// it assumes you will further manipulate this grid and DIRTY AND SAVE THE SCENE
// be sure to drop this into an Editor folder!
public class MakeGridOfSprites : EditorWindow
@kurtdekker
kurtdekker / RepeatingKeyDetector.cs
Last active January 8, 2022 20:23
Detect both edge-trigger (pressed) keys and held-to-repeat keys in Unity3D
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// @kurtdekker
//
// cheap and cheerful repeating keys in Unity3D
//
// You can lift/release them as fast as you like
// and exceed the repeat rate. Or just hold it.
@kurtdekker
kurtdekker / EditorScreenshotTaker.cs
Created January 10, 2022 19:25
take simple screenshots in Unity3D
using UnityEngine;
using System.Collections;
// @kurtdekker
// drop it in a scene somewhere or else call PossiblyAttach(),
// in which case it only attaches in the editor.
public class EditorScreenshotTaker : MonoBehaviour
{
static bool tried;
@kurtdekker
kurtdekker / RayViz.cs
Created January 13, 2022 18:56
Visualize rays in Unity using LineRenderers
using System.Collections;
using UnityEngine;
// @kurtdekker
//
// Simple way to throw visible rays into a scene using LineRenderers
//
// Useful for debugging raycasts.
//
// May be helpful to call Debug.Break() simultaneously
@kurtdekker
kurtdekker / SetRB2DCenterOfMass.cs
Created January 25, 2022 22:50
Sets center of mass on a Rigidbody2D
using UnityEngine;
// @kurtdekker
// to use, place this on the GameObject where your Rigidbody2D is located
public class SetRB2DCenterOfMass : MonoBehaviour
{
public Vector3 DesiredCenterOfMass;
void Start ()
@kurtdekker
kurtdekker / CommonStatisticsAccumulator.cs
Created February 7, 2022 14:42
Unity3D simple time-and-distance statistics accumulation
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// @kurtdekker
//
// This is the statistics accumulator that runs whenever
// a game is running in Jetpack Kurt.
//
// When your game starts call CommonStatisticsAccumulator.Attach()
@kurtdekker
kurtdekker / Flashlight.cs
Created February 12, 2022 19:38
Simple flashlight script
using UnityEngine;
using System.Collections;
// @kurtdekker
// place this on the flashlight, which must have a Light component
public class Flashlight : MonoBehaviour
{
public float battery = 20;
bool isOn;
@kurtdekker
kurtdekker / TiledSpritesInfinite.cs
Created February 23, 2022 23:27
Infinite scrolling sprite background in Unity3D
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// @kurtdekker
// To use:
// import a repeating sprite, FullRect
// drop it on a SpriteRenderer GameObject
// drop this on that same SpriteRenderer you want to be infinitely tiled
//