Skip to content

Instantly share code, notes, and snippets.

View AngryAnt's full-sized avatar

Emil "AngryAnt" Johansen AngryAnt

View GitHub Profile
@AngryAnt
AngryAnt / Hover.cs
Created July 15, 2011 09:48
Very simple hover script. Use in conjunction with WASD controller handling planar movement.
using UnityEngine;
public class Hover : MonoBehaviour
{
public float maxDistance, maxForce;
private Vector3 forceVector;
@AngryAnt
AngryAnt / PathGrid.cs
Created July 19, 2011 11:58
Simple example of building a Path grid
// Given: float width, float height, float xSpacing, float ySpacing, Vector3 gridStart
Waypoint[] points = new Waypoint[width * height];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
points[y * width + x] = new GameObject (string.Format ("Grid-{0}-{1}", x, y), typeof (Waypoint)).GetComponent<Waypoint> ();
points[y * width + x].transform.position = gridStart + Vector3.z * ySpacing + Vector3.x * xSpacing;
@AngryAnt
AngryAnt / CircleCheck.cs
Created July 21, 2011 09:37
GUI: Circular hot zone. Very simple, but not necessarily very efficient way of determining mouse presence within a circular section of GUI space.
// Given: Vector2 point, float radius, inside valid GUI context
if (new Vector2 (Event.current.mousePosition - point).magnitude < radius)
{
GUILayout.Label ("Inside");
}
else
{
GUILayout.Label ("Outside");
}
@AngryAnt
AngryAnt / LevelFlip.cs
Created July 22, 2011 08:56
GUI component flipping through the levels of the game.
void OnGUI ()
{
bool enabled = GUI.enabled;
GUI.enabled = enabled && Application.loadedLevel > 0;
if (GUILayout.Button ("Previous"))
{
Application.LoadLevel (Application.loadedLevel - 1);
}
@AngryAnt
AngryAnt / DistancePoints.cs
Created July 25, 2011 12:23
An example of tracking distance traveled and translating to game points. Untested.
using UnityEngine;
using System.Collections;
public class DistancePoints : MonoBehaviour
{
public float pointsPerUnit = 1.0f;
private Vector3 lastPosition;
@AngryAnt
AngryAnt / ComboKeys.cs
Created July 25, 2011 15:52
An example of how combo keys could be implemented via coroutines (untested).
using UnityEngine;
using System.Collections;
public class KeyCombo
{
public float maxPause = 1.0f;
public string[] keys;
public string message;
@AngryAnt
AngryAnt / RepeatDecorators.cs
Created July 26, 2011 12:02
Examples of Behave repeat decorator implementations (untested).
private Dictionary<string, int> activeRepeats = new Dictionary<string, float> ();
private Dictionary<string, float> activeTimers = new Dictionary<string, float> ();
// The repeat decorator works more or less like a for loop //
public BehaveResult InitRepeatDecorator (Tree sender, string name, float repeats, IAgent agent, object data)
@AngryAnt
AngryAnt / Multiply.cs
Created August 1, 2011 14:58
A simple example of a multiply blend in Unity. http://en.wikipedia.org/wiki/Blend_modes#Multiply
using UnityEngine;
using System.Collections;
public class Multiply : MonoBehaviour
{
public Camera source, destination;
private RenderTexture renderTexture;
@AngryAnt
AngryAnt / WebsiteCommunication.cs
Created August 3, 2011 13:21
WebPlayer - website JavaScript two-way communication example. The goal here is to keep the website JS code handy. Untested.
using UnityEngine;
using System.Collections;
public delegate void JSCallback (string value);
public class WebsiteCommunication : MonoBehaviour
{
public TextAsset stringRequest;
@AngryAnt
AngryAnt / NetworkCleanup.cs
Created August 17, 2011 09:49
Proper cleanup after players in a Unity networked game.
void OnPlayerDisconnected (NetworkPlayer player)
{
Network.RemoveRPCs (player);
Network.DestroyPlayerObjects (player);
}