Skip to content

Instantly share code, notes, and snippets.

View OutlawGameTools's full-sized avatar

J. A. Whye OutlawGameTools

View GitHub Profile
@OutlawGameTools
OutlawGameTools / MoveWithKeys.js
Created March 11, 2015 10:56
CS109 - Move a game object using the arrow keys on the keyboard.
#pragma strict
public var speed : float = 10f;
function Update () {
var move = Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
transform.position += move * speed * Time.deltaTime;
}
@OutlawGameTools
OutlawGameTools / Ship.js
Created March 12, 2015 10:35
CS109 - Attached to a ship, kills itself and instantiates an explosion when it hits a trigger2d collider.
#pragma strict
public var expl : GameObject;
function OnTriggerEnter2D (other : Collider2D)
{
var newPos : Vector3 = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0);
Instantiate(expl, newPos, Quaternion.identity);
Destroy(gameObject);
}
@OutlawGameTools
OutlawGameTools / ParticlePickup
Created March 15, 2015 22:44
CS109 - Pickup Particle Settings (no graphics)
General
Duration 0.20
Looping Off
Start Lifetime 1
Start Speed 10
Start Rotation 0-360
Emission
Rate 70
Shape
Shape Sphere
@OutlawGameTools
OutlawGameTools / Pickup.js
Last active August 29, 2015 14:17
CS109 - Attach to a coin or other pickup item. Destroys the item and optionally shows a particle effect.
#pragma strict
public var coinEffect : GameObject;
function OnTriggerEnter2D (other : Collider2D)
{
if (coinEffect)
Instantiate(coinEffect, transform.position, transform.rotation);
Destroy(gameObject);
@OutlawGameTools
OutlawGameTools / MusicTrigger.js
Created March 21, 2015 00:05
CS109 - Add to a game object with Collider2D isTrigger to start music when triggered
#pragma strict
private var aSource : AudioSource;
function Start ()
{
aSource = GetComponent.<AudioSource>();
}
function OnTriggerEnter2D ()
@OutlawGameTools
OutlawGameTools / Pickup.js
Last active August 29, 2015 14:17
CS109 - Attach to a coin or other pickup item. Destroys the item and optionally shows a particle effect and plays sound FX.
#pragma strict
public var coinEffect : GameObject;
private var soundFX : AudioSource;
function Start()
{
soundFX = GetComponent.<AudioSource>();
}
@OutlawGameTools
OutlawGameTools / PlayOnTrigger.js
Created March 21, 2015 05:06
CS109 - Starts an AudioSource playing when attached object collider2D is triggered.
#pragma strict
private var aSource : AudioSource;
function Start ()
{
aSource = GetComponent.<AudioSource>();
}
function OnTriggerEnter2D ()
@OutlawGameTools
OutlawGameTools / InstantiateGObj.js
Created March 26, 2015 00:24
CS109 - Update to old script. This is more generic. Instantiate objects at certain places.
#pragma strict
public var gObj : GameObject;
public var minX : float;
public var maxX : float;
public var minY : float;
public var maxY : float;
public var startDelay : float = 0f;
@OutlawGameTools
OutlawGameTools / Missile.js
Created April 4, 2015 05:39
CS109 - Attach to the rocket to allow firing, exploding, and resetting.
#pragma strict
public var xSpeed : int;
public var ySpeed : int;
public var randomX : boolean = false;
public var minXSpeed : int = 100;
public var maxXSpeed : int = 200;
public var randomY : boolean = false;
@OutlawGameTools
OutlawGameTools / getneighbors.lua
Created April 9, 2015 09:43
Pass in an index into a 2-dimensional square grid and get back a table containing the index of all neighbor squares.
--==============================================================
-- pass in a lily pad number and get back a
-- table containing all the neighbors for
-- that lily pad.
local numCols = 11
local numRows = 7
local function getNeighbors(padNum)