Skip to content

Instantly share code, notes, and snippets.

View kurtdekker's full-sized avatar

Kurt Dekker kurtdekker

View GitHub Profile
@kurtdekker
kurtdekker / RevolutionCounter.cs
Last active January 22, 2024 06:20
Counts revolutions of a Transform (around its +Z axis)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// @kurtdekker
//
// Counts revolutions in degrees around the +Z axis of a transform
//
// NOTE: Like all things in a discrete digital simulation, this takes samples at
// regular intervals. This means rapid rotation of the transform will introduce
@kurtdekker
kurtdekker / ScreenMetrics2D.cs
Created August 14, 2023 14:53
Unity3D screen metrics utility for 2D camera use
using UnityEngine;
// @kurtdekker
//
// Ultra simple script to give you the "live edges" of your screen.
// This updates for any screen orientation, dimensions or camera.
//
// Presumes:
// - orthographic Camera pointed +Z
// - returns values in the Z == 0 plane.
@kurtdekker
kurtdekker / RunmeJohnny.cs
Created July 22, 2023 13:54
Make a Unity project / build with zero scenes, just pure code.
using UnityEngine;
// @kurtdekker - for the purists who don't want ANY scenes in project
//
// All other Unity asset inclusion rules are still in effect, so no
// assets will make it into your project unless they are:
//
// - correctly in a Resources/ folder
// - referenced by something in the above
// - correctly in the Streaming Assets folder / system.
@kurtdekker
kurtdekker / PlatformMotionRecorder.cs
Last active July 18, 2023 04:40
Track platforms so you can ride them around reliably.
//
// @kurtdekker
//
// Purpose: to be able to track arbitrary moving surfaces
// you want to hop on and ride around (platforms, etc.)
//
// Requires you to know if you are grounded or not.
//
// To use:
//
@kurtdekker
kurtdekker / CanvasScalerOrientationDriver.cs
Created June 30, 2023 23:20
CanvasScaler Orientation Driver - controls the CanvasScaler to simplify portrait / landscape adjustments
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// @kurtdekker - to help fitting portrait / landscape UI stuff together
//
// Put this where the CanvasScaler is.
//
// You should set CanvasScaler to:
@kurtdekker
kurtdekker / LaneMover.cs
Created June 26, 2023 13:50
Lane-based motion in the X- and Z- coordinate space
using UnityEngine;
// @kurtdekker - lane-based mover
//
// To use:
// Drop this on your player object
// Move your camera to see it go into the distance (see note about 2D below)
// press PLAY
// use A and D to change lanes
@kurtdekker
kurtdekker / SimpleMouseSpeed.cs
Created June 9, 2023 18:37
Simple reporter of mouse movement speed in pixels.
using UnityEngine;
// @kurdekker - reports mouse speed in screen pixels per second.
//
// To use:
// - drop on an empty GameObject
// - make sure the console will be visible
// - press PLAY
// - wiggle your mouse
// - watch your console
@kurtdekker
kurtdekker / ChaseParent.cs
Created April 4, 2023 00:58
chase a parent transform, rotation and position only (not scale)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// @kurtdekker - used to LateUpdate()-chase another
// Transform, position and rotation only.
//
// To use, call the Attach() factory, tell it:
// - who you are that want to chase
// - the target you want to chase
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// @kurtdekker - making a structural grid in Unity3D
// to use: drop this in a blank scene and watch!
//
// NOTE: this makes a web with a central link.
// you could do other connectivity strategies obviously.
@kurtdekker
kurtdekker / MusicManager.cs
Last active January 24, 2023 04:47
Ultra simple Music Manager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// @kurtdekker - example of an ultra-simple music manager.
//
// How to use:
// MusicManager.Instance.PlayMusic( Audioclip clip);
//
// Call the above with null to stop music.