Skip to content

Instantly share code, notes, and snippets.

@keiranlovett
keiranlovett / unity: wind
Last active November 1, 2018 21:09
Custom Wind Script = random rotation around world.space
using UnityEngine;
using System.Collections;
public class windController : MonoBehaviour {
//TODO
//1) Inwards / Outwards Direction
float t;
int direction = 1; //Direction of rotation the wind object makes
@keiranlovett
keiranlovett / unity: autofocus
Created September 27, 2013 17:58
Drop DoFAutoFocus onto your Camera, be sure you have imported the ImageEffects. Adjust your DoF Settings. Script creates a new Gameobject "DoFFocusTarget" and asigns it to your DoF Image Effect. Enable interpolateFocus to use linear interpolation for the focus point. Switch Quality between NORMAL and HIGH changes the focus call from the FixedUpd…
using UnityEngine;
using System.Collections;
using System;
/// <summary>
/// PlayFM
/// DoFAutofocus.cs
///
/// HIGH Quality checks every Frame
/// NORMAL Quality in Fixed Update
@keiranlovett
keiranlovett / unity: underwater
Created September 27, 2013 18:00
Attach to your main camera and key in the y-position of your water plane for "underwaterLevel". Leave "noSkybox" blank.
using UnityEngine;
using System.Collections;
public class Underwater : MonoBehaviour {
//This script enables underwater effects. Attach to main camera.
//Define variable
public int underwaterLevel = 7;
@keiranlovett
keiranlovett / unity: compass
Created September 27, 2013 18:02
The compass script allows you to get 0-360 degree heading with respect to an arbitrary North reference object named "GPS Reference" of which the Z axis is pointed North. The compass uses a Sender to send the heading over a network.
var updateFreq = 1.0;
private var heading = 0.0;
private var gpsRef : Transform;
private var gpsRefN : int;
private var sender : Sender;
private var timer = 0.0;
function Start(){
Init();
}
@keiranlovett
keiranlovett / unity: worldTime
Created September 27, 2013 18:03
GameTime rotates a directional light to match the appropriate direction of the sun for the system time of day.
import System;
var date = DateTime.Now;
var timeDisplay : GUIText;
function Start() {
InvokeRepeating("Increment", 1.0, 1.0);
}
function Update () {
var seconds : float = date.TimeOfDay.Ticks / 10000000;
transform.rotation = Quaternion.LookRotation(Vector3.up);
@keiranlovett
keiranlovett / unity: scanner
Created September 27, 2013 18:05
This script simulates the SICK LMS laser scanner by doing a bunch of raycasts around a single point. There are two functions each behaves slightly differently. See the comments in the code. Attach this to an empty object, which becomes the scanner. You'll need some sort of query function to retrieve the range data for use in other parts of the g…
var arcAngle = 180.0;
var numLines = 181;
var maxDist = 8.0;
var scansPerSec = 3;
private var ranges : float[];
private var timer = 0.0;
function LateUpdate(){
DoScan2();
}
@keiranlovett
keiranlovett / unity: explosion
Created September 27, 2013 18:07
Simple Explosion Effect. Instantiate along with particles to throw nearby rigidbodies away from the explosion. Author: Opless
using UnityEngine;
using System.Collections;
public class OnExplosionEffect : MonoBehaviour {
public float radius = 5;
public float power = 5;
public float upwardForce = 0;
private float radiusUsed = 0.5F;
@keiranlovett
keiranlovett / unity: explosion2
Created September 27, 2013 18:08
Collide with anything, spawn an explosion prefab. Useful for missiles, grenades, etc
using UnityEngine;
using System.Collections;
public class OnCollideExplode : MonoBehaviour
{
// A grenade
// - instantiates a explosion prefab when hitting a surface
// - then destroys itself
public GameObject explosionPrefab;
@keiranlovett
keiranlovett / unity: light
Created October 17, 2013 10:33
Light controller. Fades lights
// Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden
// Do test the code! You usually need to change a few small bits.
using UnityEngine;
using System.Collections;
public class lightController : MonoBehaviour {
public bool flicker = false;
public float onTime = 2;
/*
* Playlist Object for the jPlayer Plugin
* http://www.jplayer.org
*
* Copyright (c) 2009 - 2013 Happyworm Ltd
* Dual licensed under the MIT and GPL licenses.
* - http://www.opensource.org/licenses/mit-license.php
* - http://www.gnu.org/copyleft/gpl.html
*
* Author: Mark J Panaghiston