Skip to content

Instantly share code, notes, and snippets.

View OutlawGameTools's full-sized avatar

J. A. Whye OutlawGameTools

View GitHub Profile
@OutlawGameTools
OutlawGameTools / DragWithMouse.cs
Created November 21, 2015 02:40
Drag a 2D game object using the mouse. Game Object must have a Collider2D component.
using UnityEngine;
using System.Collections;
public class DragWithMouse : MonoBehaviour {
private Vector3 offset;
void OnMouseDown () {
Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
offset = transform.position - Camera.main.ScreenToWorldPoint(mousePos);
@OutlawGameTools
OutlawGameTools / DriftingText.cs
Created September 5, 2015 03:58
Used with DOTween to make message, scores, etc., float up (or down) and fade out.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using DG.Tweening;
public class DriftingText : MonoBehaviour {
public GameObject canvas;
public GameObject textPrefab;
public float driftTime = 1f;
@OutlawGameTools
OutlawGameTools / GoToSceneButton.cs
Created September 5, 2015 03:52
Use on a UI button click event to go to another scene.
using UnityEngine;
using System.Collections;
public class GoToSceneButton : MonoBehaviour {
public void GoToScene(string sceneName)
{
Application.LoadLevel (sceneName);
}
@OutlawGameTools
OutlawGameTools / Accelerate.js
Created April 23, 2015 05:11
CS109 - Add force to a game object when mouse button is pressed; stop adding when button is up.
#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 ()
{
@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)
@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 / 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 / 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 / ShowMe.js
Last active October 3, 2015 08:09
CS109 - Enables a game object's renderer after a specified delay. Make invisible objects visible.
#pragma strict
public var showDelay : float = 0.2;
public var startHidden : bool = true;
function Awake()
{
if (startHidden)
gameObject.renderer.enabled = false;
}
@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>();
}