Skip to content

Instantly share code, notes, and snippets.

View OutlawGameTools's full-sized avatar

J. A. Whye OutlawGameTools

View GitHub Profile
@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.
#pragma strict
public var coinEffect : GameObject;
function OnTriggerEnter2D (other : Collider2D)
{
if (coinEffect)
Instantiate(coinEffect, transform.position, transform.rotation);
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 / 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 / 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 / MoveObject.js (Phase 2)
Created March 11, 2015 08:49
CS109 - A better version of MoveObject that adds randomness and is more generic.
#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 / MoveObject.js (Phase 1)
Created March 9, 2015 09:21
CS109 - Move a game object using Rigidbody2D.AddForce. (Phase 1 of this script)
#pragma strict
public var speed : int;
function Start ()
{
var newSpeed : Vector2;
newSpeed.x = speed;
newSpeed.y = 0;
@OutlawGameTools
OutlawGameTools / Particle.js
Last active August 29, 2015 14:16
CS109 - Generic utilities for particles, such as bring particle up to a named layer so it can be seen.
#pragma strict
public var layerName : String = "Foreground"; // the layer in which the particle should be placed
public var orderInLayer : int = -1; // -1 to go behind the parent object, 1 to go in front of it
public var destroyAfterTime : float = 0;
private var pSys : ParticleSystem;
function Start () {
@OutlawGameTools
OutlawGameTools / Explosion.js
Created March 9, 2015 00:33
CS109 - Attach to an explosion, it deletes it after done. Optionally kills Enemies caught inside blast radius.
#pragma strict
public var liveTime : float = 0.5f; // how long to wait before ditching the explosion
public var killWithTag : String = "Enemy"; // kills these tagged objects in the blast radius
function Start ()
{
Invoke("DeleteMe", liveTime);
}
@OutlawGameTools
OutlawGameTools / Accelerate.js
Created March 9, 2015 00:19
CS109 - Add force to a RigidBody2D when the mouse button is pressed.
#pragma strict
public var rocket : GameObject; // object to push
public var xSpeed : float = 0; // horizontal speed
public var ySpeed : float = 400; // vertical speed
private var rb2D : Rigidbody2D;
function Start ()
{