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 / GravityWell.cs
Created August 18, 2011 09:01
An example of how to easily do an inexpensive alternative gravity setup (untested).
// GravityObject.cs
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Rigidbody))]
public class GravityObject : MonoBehaviour
{
public float gravityModifier = 1.0f;
@AngryAnt
AngryAnt / ContainerGravity.cs
Created July 2, 2012 11:14
Example of simple component for keeping objects inside defined bounds by physically repelling them back when they exit.
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (BoxCollider))]
public class ContainerGravity : MonoBehaviour
{
public float strength = 10.0f;
@AngryAnt
AngryAnt / CameraControl.cs
Created July 6, 2012 12:00
Example of a clamped camera look rotation.
target.RotateAround (target.position, target.right, addedRotation);
bool lookingUp = Vector3.Angle (target.forward, Vector3.up) < Vector3.Angle (target.forward, Vector3.up * -1.0f);
float angle = Vector3.Angle (target.forward, Vector3.Cross (target.right, Vector3.up));
if (angle > forwardAngleClamp)
{
target.RotateAround (target.position, target.right, lookingUp ? angle - forwardAngleClamp : forwardAngleClamp - angle);
}
@AngryAnt
AngryAnt / Utilities.cs
Created September 29, 2012 17:59
Example code for "Logging an entire GameObject" blog post on AngryAnt.com
using UnityEngine;
using System.Reflection;
public class Utilities
{
/* ... */
static void LogGameObject( GameObject gameObject, bool children )
{
Component[] components = gameObject.GetComponents( typeof( Component ) );
@AngryAnt
AngryAnt / MultiScene.cs
Created August 9, 2013 10:03
This utility lets you easily combine two scenes into one.
using UnityEngine;
using UnityEditor;
using System.IO;
public class MultiScene
{
[MenuItem ("File/Combine Scenes")]
static void Combine ()
{
//#define DEBUG_THREADING
using UnityEngine;
using System.Collections;
using System.Threading;
using System.Reflection;
public delegate IEnumerator MonitorCoroutine<T> (CoroutineData<T> data);
@AngryAnt
AngryAnt / DualDisplay.cs
Last active January 24, 2024 08:26
Example use of the Unity 4.1 AirPlay API - gives a setup with the iOS device as controller of the remote display.
using UnityEngine;
using System.Collections;
/*
Runtime use:
To be available, AirPlay needs to be switched on for the device either via a native AirPlay UI component or
via the global AirPlay mirroring setting. Your options are:
A: Modify your Xcode project to layer a native AirPlay Cocoa control somewhere over your Unity content.
@AngryAnt
AngryAnt / MissingHassModule.sh
Last active July 31, 2023 17:51
List the home assistant modules reported missing by the nixos home assistant service since it was last started.
#!/usr/bin/env bash
set -euo pipefail
serviceName="home-assistant.service"
startTime=$(systemctl show -p ActiveEnterTimestamp "$serviceName")
startTime=$(echo $startTime | awk '{print $2 $3}')
echo "Missing modules reported since $serviceName start at $startTime:"
@AngryAnt
AngryAnt / TerriblyHackyLog.cs
Created August 7, 2013 18:04
Abusing reflection and the internal Unity player build error function to get stacktrace-less error logs. Not recommended for anything sane.
using UnityEngine;
using System.Reflection;
public class TerriblyHackyLog : MonoBehaviour
{
void Start ()
{
Log ("Aaaaarrrrgh!");
}