Skip to content

Instantly share code, notes, and snippets.

Avatar

Kurt Dekker kurtdekker

View GitHub Profile
@kurtdekker
kurtdekker / RayViz.cs
Created Jan 13, 2022
Visualize rays in Unity using LineRenderers
View RayViz.cs
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 / EditorScreenshotTaker.cs
Created Jan 10, 2022
take simple screenshots in Unity3D
View EditorScreenshotTaker.cs
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 / RepeatingKeyDetector.cs
Last active Jan 8, 2022
Detect both edge-trigger (pressed) keys and held-to-repeat keys in Unity3D
View RepeatingKeyDetector.cs
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 / MakeGridOfSprites.cs
Created Dec 8, 2021
Editor script to make a grid of sprites, aka, poor man's tilemap
View MakeGridOfSprites.cs
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 / LateFollow.cs
Created Nov 18, 2021
Lets one object follow another object using only a positional offset
View LateFollow.cs
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 / JsonPlayerPrefs.cs
Created Oct 16, 2021 — forked from brettmjohnson/JsonPlayerPrefs.cs
A replacement for Unity's PlayerPrefs that stores data in a JSON file.
View JsonPlayerPrefs.cs
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 / ScaleOnFocus.cs
Created Oct 12, 2021
Simple focused-button animator
View ScaleOnFocus.cs
using UnityEngine;
using UnityEngine.EventSystems;
// @kurtdekker
// cheap and cheerful "increase the size of the focused button"
public class ScaleOnFocus : MonoBehaviour
{
[Header( "Percent increase +10%, etc.")]
public float PercentIncrease = 10;
@kurtdekker
kurtdekker / InGamePause.cs
Created Oct 10, 2021
Simple stateless in-game pause mechanism
View InGamePause.cs
using UnityEngine;
// @kurtdekker
// Ultra-simple clean stateless in-game pause/unpause mechanism.
// TODO:
// - put one of these script instances in your running game scene
// - be sure to set Time.timeScale = 1 when your game starts
public class InGamePause : MonoBehaviour
{
@kurtdekker
kurtdekker / ReadInputManager.cs
Created Sep 20, 2021
Display and Test ALL Unity3D inputs (old Input System)
View ReadInputManager.cs
using UnityEngine;
using System.Collections;
using UnityEditor;
// @kurtdekker
// You must put this in an Editor folder!
// Once compiled, you must run it from Menu -> Assets -> ReadInputManager
public class ReadInputManager
View GM.cs
//
// @kurtdekker
//
// ULTRA-simple fully-static GameManager for simple arcade-style games.
//
// NOTE: you DO NOT place this file into any scene! It is a pure static data container.
//
// Usage:
// - at start of game call GM.InitGame()
// - when you earn points, call GM.AddPoints(1234);