Skip to content

Instantly share code, notes, and snippets.

View OutlawGameTools's full-sized avatar

J. A. Whye OutlawGameTools

View GitHub Profile
@OutlawGameTools
OutlawGameTools / GameData.js
Created March 2, 2015 06:13
CS109 - A place to store our score variables.
#pragma strict
// access from other scripts like GameData.numGrabbed++
static var numGrabbed : int = 0;
static var numMissed : int = 0;
static function DisplayScore () {
Debug.Log("Grabbed: " + numGrabbed + " Missed: " + numMissed);
@OutlawGameTools
OutlawGameTools / InstantiateGObj.js
Created March 2, 2015 05:50
CS109 - Instantiate (clone) a game object in the scene. Also shows InvokeRepeating() to clone multiples
#pragma strict
public var gObj : GameObject;
function Start () {
InvokeRepeating("CreateRandom", 0, 4);
}
function CreateRandom ()
{
@OutlawGameTools
OutlawGameTools / BombHit.js
Created March 2, 2015 05:37
CS109 - Destroy the game object when it collides with a specific object (based on tag).
#pragma strict
public var hitTag : string = "Ground";
function OnCollisionEnter2D (other : Collision2D)
{
if (other.gameObject.CompareTag(hitTag))
{
GameData.numMissed++;
GameData.DisplayScore();
@OutlawGameTools
OutlawGameTools / DestroyOnClick.js
Last active August 29, 2015 14:16
CS109 - Destroy the game object when clicked on. Game object must have a collider component.
#pragma strict
function OnMouseDown ()
{
if (gameObject.transform.position.y > -2 && gameObject.transform.position.y < 4)
{
GameData.numGrabbed++;
GameData.DisplayScore();
Destroy(gameObject);
}
@OutlawGameTools
OutlawGameTools / pickups.js
Created February 11, 2015 22:13
Unity: Attach to game objects that can be picked up (collider2d, isTrigger). Play audio if it exists on game object.
#pragma strict
public var pickupValue : int = 5;
function OnTriggerEnter2D(other : Collider2D)
{
var gObj : GameObject = other.gameObject;
var clip : AudioClip;
if (gObj.CompareTag("Player"))
@OutlawGameTools
OutlawGameTools / coinToss.lua
Created January 31, 2015 22:00
Corona: Returns true or false, randomly. Optionally pass in an int up to 100 to "weight" how often true is returned.
local function coinToss(weighted)
local w = weighted or 50
return math.random() <= w/100
end