Skip to content

Instantly share code, notes, and snippets.

View samsheffield's full-sized avatar
🏠
Homing from work

Sam Sheffield samsheffield

🏠
Homing from work
View GitHub Profile
@samsheffield
samsheffield / TrinketKeyboardEmulator.ino
Last active September 22, 2017 13:00
Basic keyboard example for Adafruit Trinket with simultaneous input
// 3 button keyboard emulator for the 5V Adafruit Trinket.
// Requires the Trinket Keyboard Library from Adafruit (https://github.com/adafruit/Adafruit-Trinket-USB/archive/master.zip)
#include <TrinketKeyboard.h>
// Array to hold keypresses. Trinket can emulate 3 simultaneously pressed keys
uint8_t pressedKeys[3];
void setup() {
// Each pin* uses internal pullup resistors
@samsheffield
samsheffield / ProTrinketKeyboardEmulator.ino
Last active September 27, 2017 12:40
Basic keyboard example for Adafruit Pro Trinket with simultaneous input
// This requires Adafruit's Pro Trinket Keyboard library
#include <ProTrinketKeyboard.h>
// Array to hold keypresses.
uint8_t pressedKeys[9];
void setup() {
// Each pin uses internal pullup resistors
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
@samsheffield
samsheffield / QuitAndReset.cs
Created October 9, 2020 19:03
Basic example of quit and reset functionality in Unity 3D
// Simple quit and escape functionality
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// First, add this...
using UnityEngine.SceneManagement;
public class QuitAndReset : MonoBehaviour
// Code based on CameraFacingBillboard by Nei Carter: http://wiki.unity3d.com/index.php?title=CameraFacingBillboard
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Billboard : MonoBehaviour
{
public Transform cameraTransform;
@samsheffield
samsheffield / TriggerScene.cs
Last active September 15, 2021 16:13
2D Game Design F21 Bonus Materials
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Add SceneManagement to switch scenes
using UnityEngine.SceneManagement;
public class TriggerScene : MonoBehaviour
{
// Create a string variable that you can set in the Inspector to specify the name of your new scene. You don't need quotes there.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyingThings : MonoBehaviour
{
// This example assumes you will use collision to destroy something. You can use the code inside of OnTriggerEnter2D as well
private void OnCollisionEnter2D(Collision2D collision)
{
// If the other thing has a specific tag. It's a good idea to limit the detection to specific things
@samsheffield
samsheffield / FlapControl.txt
Last active September 25, 2021 21:04
Flapping movement
Here is a bonus Unity example for 2D Game Design F21. Let me know what else you need!
======================================================================================
A BASIC APPROACH TO FLAPPING
Full example: FlappyControl.cs
Important:
1. Flapping isn't exactly jumping. Our expectations of jumping in videogames tend to be much higher. This is dumb, bouncy, and messy (but fun!)
2. Your GameObject needs a Rigidbody2D component with Gravity Scale set to something other than 0.
3. The script interact's a lot with the Rigidbody2D properties Gravity Scale and Linear Drag. Experiment!
@samsheffield
samsheffield / KeyControl.cs
Created September 25, 2021 21:56
Using specific keys instead of Axis Input
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KeyControl : MonoBehaviour
{
// Variables for keycodes that can be set in the Inspector
public KeyCode up = KeyCode.W;
public KeyCode down = KeyCode.S;
public KeyCode left = KeyCode.A;
@samsheffield
samsheffield / JustOnce.cs
Created September 27, 2021 00:40
How to do something just once in Update
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JustOnce : MonoBehaviour
{
// Has the thing already been done?
private bool alreadyDone = false;
@samsheffield
samsheffield / SwitchScene.cs
Created September 28, 2021 08:36
Load a scene with a keypress
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement; // Add Scene Management
public class SwitchScene : MonoBehaviour
{
// Important: Don't forget to add the next scene to your project's Build Settings