Skip to content

Instantly share code, notes, and snippets.

@grimmdev
grimmdev / UnityC#SpriteURL
Created June 18, 2014 00:56
Load Sprite Dynamically from URL using C#
// yay! using statements!
using UnityEngine;
using System.Collections;
// this is pish posh class stuff!
public class SpriteChangeExample : MonoBehaviour {
// we create a variable to store our sprite renderer for easy referencing and set to empty/null.
private SpriteRenderer thisSprite = null;
// we now create a variable for our polygon collider so our sprite has a neat new 2dcollider that fits comfortably!
@grimmdev
grimmdev / 0_reuse_code.js
Last active August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@grimmdev
grimmdev / SimplexNoiseGenerator.cs
Created October 23, 2014 05:55
Noise Generator
using UnityEngine;
using System.Collections;
public class SimplexNoiseGenerator {
private int[] A = new int[3];
private float s, u, v, w;
private int i, j, k;
private float onethird = 0.333333333f;
private float onesixth = 0.166666667f;
private int[] T;
@grimmdev
grimmdev / Screenshot.cs
Created October 24, 2014 02:29
Simple class for Screenshots in Unity, no need to attach it to any object, just call the Capture function and use, contains 2 constructors.
using UnityEngine;
using System.Collections;
public static class Screenshot
{
private static string GetTimestamp () {
System.DateTime dateTime = System.DateTime.Now;
return dateTime.ToString("yyyyMMddHHmmss");
}
@grimmdev
grimmdev / ScreenManager.cs
Created October 24, 2014 02:42
Useful for getting world cordinates of screen limits in both ortho and perspective camera types.
using UnityEngine;
using System.Collections;
public class ScreenManager : MonoBehaviour
{
// mouse position in screen cordinates.
public Vector3 screenPosition;
// mouse position in world space.
public Vector3 worldPosition;
// Bounds of the screen in world space.
@grimmdev
grimmdev / ObjectViewer.cs
Created October 24, 2014 03:19
ObjectViewer for 3d models in 3d space. The concept is based off of Tomb Raider and Skyrim respectively.
using UnityEngine;
using System.Collections;
public class ObjectViewer : MonoBehaviour {
// Object or Transform which we want to rotate
public Transform targetObject;
// these are the import but hush hush settings for the rotation properties
public RotationProperties rotationProperties;
@grimmdev
grimmdev / CameraShake.cs
Created October 24, 2014 03:24
Simple to use, adds the ability to shake your Camera, with little to no effort, includes 3 constructors.
using UnityEngine;
using System.Collections;
public class CameraShake : MonoBehaviour{
private static Vector3 originPosition;
private static Quaternion originRotation;
private static float shakeDecay = 0.002f;
private static float shakeIntensity;
@grimmdev
grimmdev / MultiplayerServer.cs
Created November 2, 2014 07:14
Simple Server/Connect
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MultiplayerServer: MonoBehaviour
{
// Server Settings
public int maxPlayers = 11;
// Player Settings
@grimmdev
grimmdev / SightCone.cs
Created November 12, 2014 04:33
Unity Cone of Sight
public static bool Sight (Vector3 target, Vector3 myPos, Vector3 myViewDir, float myViewDist, float myViewAng) {
bool res = false;
float ang = Vector2.Angle(DirGet2D(myPos, target), VecGet2D(myViewDir));
if (ang <= (myViewAng/2f)) {
if (DistGet2D(myPos, target) < myViewDist)
res = true;
}
return res;
}
@grimmdev
grimmdev / Key.php
Last active August 19, 2016 08:34
CD Key Generator!
// Sean Loper
// I use a template so any combination can be used, logically.
// Every X is replaced by a random character while 9 is replaced by a random number!
function randomKey()
{
$template = 'XX99-XX99-99XX-99XX-XXXX-99XX';
$k = strlen($template);
$sernum = '';
for ($i=0; $i<$k; $i++)
{