Skip to content

Instantly share code, notes, and snippets.


Emil Johansen AngryAnt

View GitHub Profile
AngryAnt / gist:7080116
Created Oct 21, 2013
Silly workaround for easy alpha scaling on the Unity Color type.
View gist:7080116
public static Color A (this Color color, float alphaScale)
return new Color (color.r, color.g, color.b, color.a * alphaScale);
// Gizmos.color = (0.3f);
AngryAnt / ConstructorIsh.cs
Created Oct 16, 2013
For when you really want that one line for instantiation and initialisation.
View ConstructorIsh.cs
class MyBehaviour : MonoBehaviour
public MyBehaviour Init (int some, float parameters)
return this;
AngryAnt / MultiScene.cs
Created Aug 9, 2013
This utility lets you easily combine two scenes into one.
View MultiScene.cs
using UnityEngine;
using UnityEditor;
using System.IO;
public class MultiScene
[MenuItem ("File/Combine Scenes")]
static void Combine ()
AngryAnt / TerriblyHackyLog.cs
Created Aug 7, 2013
Abusing reflection and the internal Unity player build error function to get stacktrace-less error logs. Not recommended for anything sane.
View TerriblyHackyLog.cs
using UnityEngine;
using System.Reflection;
public class TerriblyHackyLog : MonoBehaviour
void Start ()
Log ("Aaaaarrrrgh!");
AngryAnt / Controllers.cs
Created Aug 4, 2013
Adding axes to the Unity input manager. As described in the post
View Controllers.cs
public static void AddAxis (AxisDefinition axis)
if (AxisDefined (
throw new System.ArgumentException (string.Format ("Specified axis \"{0}\" already exists",;
SerializedObject serializedObject = new SerializedObject (AssetDatabase.LoadAllAssetsAtPath ("ProjectSettings/InputManager.asset")[0]);
SerializedProperty axesProperty = serializedObject.FindProperty ("m_Axes");
AngryAnt / Digits.cs
Last active Dec 20, 2015
Display an integral value in separate textures of digits. Untested.
View Digits.cs
Texture2D[] m_Numbers, m_Digits;
void SetValue (int value)
if (value >= Mathf.Pow (10, m_Digits.Length))
Debug.LogError ("Value overflow: Unable to display value: " + value);
for (int i = m_Digits.Length - 1; i >= 0; --i)
AngryAnt / Control-OnGesture.cs
Created Jul 19, 2013
Example of an OnGesture handler - handling left and right swipes as served up by the TouchGestures component.
View Control-OnGesture.cs
void OnGesture (Gesture gesture)
switch (gesture.type)
case GestureType.Swipe:
if (Vector2.Dot (gesture.direction, new Vector2 (1.0f, 0.0f)) > 0.8f)
Previous ();
else if (Vector2.Dot (gesture.direction, new Vector2 (-1.0f, 0.0f)) > 0.8f)
AngryAnt / OnRenderTextureGUI.cs
Created Jul 12, 2013
Example code for "OnRenderTextureGUI" blog post on
View OnRenderTextureGUI.cs
void OnGUI ()
BeginRenderTextureGUI (m_TargetTexture);
GUILayout.Box ("This box goes on a render texture!");
EndRenderTextureGUI ();
AngryAnt / Broadcaster.cs
Created Jun 7, 2013
Broadcaster / Seeker basics for sharing and joining games on your local network. Example code for "The implicit local network interface" blog post on
View Broadcaster.cs
if (m_BroadcastTimer == null)
// Setup broadcast of hosting service
m_BroadcastSocket = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPAddress broadcastGroup = IPAddress.Parse (kBroadcastGroup);
m_BroadcastSocket.SetSocketOption (
AngryAnt / Pickup.cs
Created May 28, 2013
Example of a server-side managed pickup base behaviour for Unity networking.
View Pickup.cs
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Collider))]
[RequireComponent (typeof (NetworkView))]
public abstract class Pickup : MonoBehaviour
bool available;
You can’t perform that action at this time.