Scripts

One of the best things about Unity is the community. Trite, perhaps, but true. (Note: unless otherwise stated, the works below are not mine.)

Asset Store

The most visible part of this is probably the Asset Store, where you can download and/or buy loads of useful stuff. The philosophy, put simply, is: Why spend a week coding something when you can just buy it for $20? Time is money, and $20 to save a week is ridiculously good value. Even more so when you realise what you’re buying may well be better than what you’d have coded.

Other Places

But the Asset Store is only scratching the surface. There are tonnes of free snippets all over the web, some of which are really useful.

  • Unify Community Wiki – if in doubt, start here. Shaders, scripts, particle effects galore. If you make something nice, consider putting it here.
    • Don’t Go Through Things – a basic solution to stop colliders travelling right through each other when at high speed (travelling further in one FixedUpdate than their own length). Your usage may require modification though.
    • Frames Per Second – various scripts (to attach to a GUIText object,) which display frame rate.
    • Camera Facing Billbard – attach this to a textured plane to make it always face the selected camera. I.e. a single particle.
  • Console script – sticking this in your scene gives you an in-game console window upon pressing ` (or whatever you re-bind it to) which displays everything you’ve written to Debug.Log() and its siblings.
  • Coroutiner [1] – in Unity, coroutines must be executed using Monobehaviour.StartCoroutine(myCoroutine()) from an instance of a MonoBehaviour. This allows coroutines to be run from anywhere, including statics. (detailed in footnote but NOT MY WORK!)

Fotenoots

[1] Coroutiner script (C#)
using UnityEngine;
using System.Collections;
/// <summary>
/// Author:         Sebastiaan Fehr (Seb@TheBinaryMill.com)
/// Date:           March 2013
/// Summary:        Creates MonoBehaviour instance through which 
///                 static classes can call StartCoroutine.
/// Description:    Classes that do not inherit from MonoBehaviour, or static 
///                 functions within MonoBehaviours are inertly unable to 
///                 call StartCoroutine, as this function is not static and 
///                 does not exist on Object. This Class creates a proxy though
///                 which StartCoroutine can be called, and destroys it when 
///                 no longer needed.
/// </summary>
public class Coroutiner {
    public static Coroutine StartCoroutine(IEnumerator iterationResult) {
        //Create GameObject with MonoBehaviour to handle task.
        GameObject routineHandlerGo = new GameObject("Coroutiner");
        CoroutinerInstance routineHandler = routineHandlerGo.AddComponent(typeof(CoroutinerInstance)) as CoroutinerInstance;
        return routineHandler.ProcessWork(iterationResult);
    }
}
public class CoroutinerInstance : MonoBehaviour {
    public Coroutine ProcessWork(IEnumerator iterationResult) {
        return StartCoroutine(DestroyWhenComplete(iterationResult));
    }
    public IEnumerator DestroyWhenComplete(IEnumerator iterationResult) {
        yield return StartCoroutine(iterationResult);
        Destroy(gameObject);
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s