Skip to content

Instantly share code, notes, and snippets.

@keiranlovett
keiranlovett / GlitchEffect.shader
Created January 31, 2014 12:25
Unity: Glitch Effect
// This work is licensed under a Creative Commons Attribution 3.0 Unported License.
// http://creativecommons.org/licenses/by/3.0/deed.en_GB
//
// You are free:
//
// to copy, distribute, display, and perform the work
// to make derivative works
// to make commercial use of the work
@keiranlovett
keiranlovett / CustomEventObj
Created January 31, 2014 11:30
Unity: Event Manager
/*
* Setup:
* Create an empty GameObject and add the EventManager script to it.
* Create custom event classes that extend the CustomEvent.
*
* Restrictions & Tips:
* DO NOT add event listeners in the Awake() method!
* This is used by the EventManager to initialize.
* Change this class' Execution Order to before default time if you need to work around this.
* Use the Start() method to setup your events.
/* Written by Cassius Adams for the Super Space Trooper video game. http://www.SuperSpaceTrooper.com */
// Find the distance between weapon and Player so we can anticipate where Player will be
distance = Vector3.Distance(player.transform.position, transform.position);
// Divide distance by weaponSpeed to see how long it will take to get from Enemy to Player
var travelTime = distance / (Mathf.Abs(weaponSpeed) + playerSpeed);
// Multiply the amount of time by the speed the Player moves at
var futurePosition = travelTime * playerSpeed;
/*
* Playlist Object for the jPlayer Plugin
* http://www.jplayer.org
*
* Copyright (c) 2009 - 2013 Happyworm Ltd
* Dual licensed under the MIT and GPL licenses.
* - http://www.opensource.org/licenses/mit-license.php
* - http://www.gnu.org/copyleft/gpl.html
*
* Author: Mark J Panaghiston
@keiranlovett
keiranlovett / unity: light
Created October 17, 2013 10:33
Light controller. Fades lights
// Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden
// Do test the code! You usually need to change a few small bits.
using UnityEngine;
using System.Collections;
public class lightController : MonoBehaviour {
public bool flicker = false;
public float onTime = 2;
@keiranlovett
keiranlovett / unity: explosion2
Created September 27, 2013 18:08
Collide with anything, spawn an explosion prefab. Useful for missiles, grenades, etc
using UnityEngine;
using System.Collections;
public class OnCollideExplode : MonoBehaviour
{
// A grenade
// - instantiates a explosion prefab when hitting a surface
// - then destroys itself
public GameObject explosionPrefab;
@keiranlovett
keiranlovett / unity: explosion
Created September 27, 2013 18:07
Simple Explosion Effect. Instantiate along with particles to throw nearby rigidbodies away from the explosion. Author: Opless
using UnityEngine;
using System.Collections;
public class OnExplosionEffect : MonoBehaviour {
public float radius = 5;
public float power = 5;
public float upwardForce = 0;
private float radiusUsed = 0.5F;
@keiranlovett
keiranlovett / unity: scanner
Created September 27, 2013 18:05
This script simulates the SICK LMS laser scanner by doing a bunch of raycasts around a single point. There are two functions each behaves slightly differently. See the comments in the code. Attach this to an empty object, which becomes the scanner. You'll need some sort of query function to retrieve the range data for use in other parts of the g…
var arcAngle = 180.0;
var numLines = 181;
var maxDist = 8.0;
var scansPerSec = 3;
private var ranges : float[];
private var timer = 0.0;
function LateUpdate(){
DoScan2();
}
@keiranlovett
keiranlovett / unity: worldTime
Created September 27, 2013 18:03
GameTime rotates a directional light to match the appropriate direction of the sun for the system time of day.
import System;
var date = DateTime.Now;
var timeDisplay : GUIText;
function Start() {
InvokeRepeating("Increment", 1.0, 1.0);
}
function Update () {
var seconds : float = date.TimeOfDay.Ticks / 10000000;
transform.rotation = Quaternion.LookRotation(Vector3.up);
@keiranlovett
keiranlovett / unity: compass
Created September 27, 2013 18:02
The compass script allows you to get 0-360 degree heading with respect to an arbitrary North reference object named "GPS Reference" of which the Z axis is pointed North. The compass uses a Sender to send the heading over a network.
var updateFreq = 1.0;
private var heading = 0.0;
private var gpsRef : Transform;
private var gpsRefN : int;
private var sender : Sender;
private var timer = 0.0;
function Start(){
Init();
}