Skip to content

Instantly share code, notes, and snippets.

View troy-lamerton's full-sized avatar

Troy troy-lamerton

  • 16:40 (UTC +12:00)
View GitHub Profile
var hashIndex = window.location.href.indexOf('#'); // 31
var stringBeforeHash = window.location.href.slice(0, hashIndex);
console.info('new href', stringBeforeHash);
window.location.href = stringBeforeHash;

Common code snippets

void RestartGame() {
    SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
void PauseGame () {
    Time.timeScale = 0;
 // ShowPauseMenu();
using UnityEngine;
public class TopDownMovement : MonoBehaviour {
public float walkSpeed = 5f;
public Boundary boundary; // optional rectangle boundary
float maxSpeed = 10f;
float curSpeed;
/* GameStatus.cs */
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class GameStatus : MonoBehaviour {
// There are 3 major ways to persist this data between scene changes.
// 1) Save the info into something persist (PlayerPrefs, a save file)
// - This preserves data even between game executions, not just scene changes
@troy-lamerton
troy-lamerton / GlobalState.cs
Created April 20, 2017 07:13
Example of global state script in unity. Doesn't need to be attached to any object, just call its methods and read its properties.
using UnityEngine;
public class GlobalState {
// bool paused = false;
public static int goop = 80;
public static int waveNumber = 1;
public static bool paused = false;
public static void AddGoop (int amount) {
goop += amount;
@troy-lamerton
troy-lamerton / GetGoop.cs
Created April 20, 2017 07:20
Gathering resource from fixed location. Script increases resource every second the player is colliding with me
using System.Collections;
// using System.Collections.Generic;
using UnityEngine;
public class GetGoop : MonoBehaviour {
Coroutine mining;
void OnTriggerEnter (Collider coll) {
using UnityEngine;
public class TopDownMovement : MonoBehaviour {
public float walkSpeed = 5f;
public Boundary boundary; // optional rectangle boundary
float maxSpeed = 10f;
float curSpeed;
// short-hand functions
const pythag = (a, b) => Math.sqrt(a * a + b * b);
console.log(pythag(3, 4));
// es6 classes
class Dog {
constructor(anyType = 'nothing', cute = false) {
this.talkThis = anyType;
this.cute = cute;
this.speak = this.speak.bind(this);
[
{
"name": "Aruba",
"callingCode": "297",
"translations": {
"de": "Aruba",
"jp": "アルバ"
},
"code": "AW"
},
@troy-lamerton
troy-lamerton / hide certain github file diffs.js
Last active March 8, 2018 13:38
run in browser console
// toggle the show/hide for file diffs in github pull requests
// this script hides all files with 'zipkey-icons' in the name
// and the language files
var fileDiffs = document.querySelectorAll('.file-header.js-file-header');
for (const fileDiff of fileDiffs) {
const text = fileDiff.innerText;
if (text.includes('zipkey-icons') || text.includes('/languages')) {
const hideButton = fileDiff.querySelector('.btn-octicon.js-details-target[aria-expanded="true"]');
hideButton && hideButton.click()