Skip to content

Instantly share code, notes, and snippets.

View AngryAnt's full-sized avatar

Emil "AngryAnt" Johansen AngryAnt

View GitHub Profile
@AngryAnt
AngryAnt / DisableKey.cs
Created September 29, 2012 17:56
Example code for "I bet you can't type an A!" blog post on AngryAnt.com
private string text = "I bet you can't type an A!";
static void DisableKeys( KeyCode[] keys )
{
if( !Event.current.isKey )
{
return;
}
@AngryAnt
AngryAnt / ComponentLister.cs
Created September 29, 2012 17:52
Example code for "Where did that component go?" blog post on AngryAnt.com
using UnityEngine;
using UnityEditor;
using System.Collections;
public class ComponentLister : EditorWindow
{
private Hashtable sets = new Hashtable();
private Vector2 scrollPosition;
@AngryAnt
AngryAnt / Magnetic.cs
Created September 29, 2012 15:52
Example code for "Magnetic" blog post on AngryAnt.com
using UnityEngine;
using System.Collections;
public class Magnetic : MonoBehaviour
{
public LayerMask m_MagneticLayers;
public Vector3 m_Position;
public float m_Radius;
public float m_Force;
@AngryAnt
AngryAnt / Null.cs
Created September 29, 2012 15:48
Example code for "Optimising coroutine yielding in C#" blog post on AngryAnt.com
private IEnumerator DoFadeAlphaIn ()
{
while (m_Alpha < 1.0f)
{
m_Alpha += Time.deltaTime;
yield return null;
}
m_Alpha = 1.0f;
}
@AngryAnt
AngryAnt / SelectableObject.cs
Created September 29, 2012 15:40
Example code for "Pick me! Pick me!" blog post on AngryAnt.com
using UnityEngine;
public class SelectableObject : MonoBehaviour
{
public Rect m_SelectionWindowRect = new Rect (10.0f, 10.0f, 300.0f, 100.0f);
public void OnMouseDown ()
{
SelectionManager.Select (gameObject, !SelectionManager.IsSelected (gameObject));
}
@AngryAnt
AngryAnt / RestartBluetooth.scpt
Created September 28, 2012 08:51
Restart the bluetooth radio on OS X using http://www.frederikseiffert.de/blueutil/
do shell script "sudo /usr/local/bin/blueutil off" with administrator privileges
delay 5
do shell script "sudo /usr/local/bin/blueutil on" with administrator privileges
@AngryAnt
AngryAnt / AssemblyTest-1.cs
Created July 23, 2012 18:50
Example code for "Assembling and Assimilating" blog post on AngryAnt.com
#if DEBUG
Debug.Log ("I'm only visible in debug builds!");
#endif
@AngryAnt
AngryAnt / PlayerController.cs
Created July 20, 2012 07:38
Example of very simple WASD + mouse controller.
using UnityEngine;
using System.Collections;
public class PlayerController : MovementController
{
public float speed = 5.0f, rotationSpeed = 50.0f;
void Update ()
@AngryAnt
AngryAnt / Network.cs
Created July 19, 2012 13:43
Getting your own IP in C#. No error testing what so ever.
using System.Linq;
using System.Net.Sockets;
using System.Net;
public static IPAddress IP
{
get
{
if (ip == null)
@AngryAnt
AngryAnt / AdditiveAim.cs
Created July 8, 2012 08:38
Animating aim additively by adjusting time.
void AnimateAdditiveAim ()
// Optionally using additive animation to visualize look. Alternative is procedural look.
{
if (aimAnimations == null)
{
return;
}
aimAnimations.NormalizedTime = 0.0f;