Skip to content

Instantly share code, notes, and snippets.

@N-Carter
N-Carter / ParticleInjector.cs
Created April 24, 2011 10:46
A component that acts like a ParticleEmitter but injects particles into other emitters
using UnityEngine;
using System.Collections;
// This component can emit particles into one or more ParticleEmitters. As several ParticleInjectors can emit to a shared set of
// ParticleEmitters, this allows you to save draw calls by having fewer separate particle systems.
//
// Note that when a ParticleEmitter's Simulate In World Space checkbox is off, it's OK to attach ParticleInjectors to separate
// hierarchies and move them independently. If it's turned on, the ParticleInjectors really need to be children of the emitter
// for the emission behaviour to make sense.
@N-Carter
N-Carter / Ship.cs
Created May 5, 2011 22:36
Simple ship controls
protected override void FixedUpdate()
{
if(m_Controls != null)
{
float turnFactor = Mathf.Lerp(1.0f, 0.5f, m_Controls.thrust);
rigidbody.AddRelativeTorque(Vector3.right * m_Controls.pitch * m_PitchFactor * turnFactor);
rigidbody.AddRelativeTorque(Vector3.forward * m_Controls.roll * m_RollFactor * turnFactor);
rigidbody.AddRelativeTorque(Vector3.up * m_Controls.yaw * m_YawFactor * turnFactor);
@N-Carter
N-Carter / PathEditor.cs
Created May 27, 2011 22:35
Path editor script
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
[CustomEditor(typeof(Path))]
public class PathEditor : Editor
{
protected Path m_Path;
@N-Carter
N-Carter / AdditiveClipsafe.shader
Created June 2, 2011 21:05
Additive Clipsafe shader
// Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position
// Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION'
// Upgrade NOTE: replaced 'glstate.matrix.modelview[0]' with 'UNITY_MATRIX_MV'
// By Daniel Brauer, with minor changes to make it additive.
Shader "Particles/Additive Clipsafe"
{
Properties
@N-Carter
N-Carter / Path.cs
Created June 16, 2011 22:59
Spline path component
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
[AddComponentMenu("Paths/Path")]
public class Path : MonoBehaviour, IEnumerable<Path.Segment>
{
[System.Serializable]
public class Waypoint : System.ICloneable
@N-Carter
N-Carter / PathTest.cs
Created June 16, 2011 23:02
Various experiments in spline interpolation
using UnityEngine;
using System.Collections;
[AddComponentMenu("Paths/Path Test")]
public class PathTest : MonoBehaviour
{
public Transform[] m_Transforms;
public int m_Divisions;
public float m_Tension;
public float m_Bias;
@N-Carter
N-Carter / ListExtension.cs
Created July 21, 2011 09:55
Generic List extension method
using System;
using System.Collections.Generic;
namespace Testbed
{
static class Extensions
{
public static T ElementFromWrappedIndex<T>(this List<T> list, int i)
{
return list[i];
@N-Carter
N-Carter / UnlitAlpha.shader
Created August 7, 2011 13:32
Shader that gets its colour from a property and its alpha from a texture
Shader "Mine/Unlit Alpha"
{
Properties
{
_Color ("Tint", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
@N-Carter
N-Carter / SpatialCutoffTest.shader
Created August 21, 2011 20:05
Geometry clipping shader
Shader "Mine/Spatial Cutoff Test"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Cutoff ("Cutoff", Float) = 1
}
SubShader
@N-Carter
N-Carter / StickOnContact.cs
Created September 3, 2011 09:36
Adding a HingeJoint component
using UnityEngine;
using System.Collections;
public class StickOnContact : MonoBehaviour
{
public Collider m_Contactor;
void OnCollisionEnter(Collision collisionInfo)
{
foreach(ContactPoint contact in collisionInfo.contacts)