Skip to content

Instantly share code, notes, and snippets.

View troy-lamerton's full-sized avatar

Troy troy-lamerton

  • 02:04 (UTC +12:00)
View GitHub Profile
using UnityEngine;
public class TopDownMovement : MonoBehaviour {
public float walkSpeed = 5f;
public Boundary boundary; // optional rectangle boundary
float maxSpeed = 10f;
float curSpeed;
@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) {
@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;
/* 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
using UnityEngine;
public class TopDownMovement : MonoBehaviour {
public float walkSpeed = 5f;
public Boundary boundary; // optional rectangle boundary
float maxSpeed = 10f;
float curSpeed;

Common code snippets

void RestartGame() {
    SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
void PauseGame () {
    Time.timeScale = 0;
 // ShowPauseMenu();
var hashIndex = window.location.href.indexOf('#'); // 31
var stringBeforeHash = window.location.href.slice(0, hashIndex);
console.info('new href', stringBeforeHash);
window.location.href = stringBeforeHash;