Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@unitycoder
unitycoder / Physics2DRaycast.cs
Last active August 29, 2015 14:18
Physics2D.Raycast
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public LayerMask targetLayer;
Vector3 prevPos;
void Start () {
@unitycoder
unitycoder / ClearPrefs
Created April 20, 2015 20:39
Reset Build Resolution Settings in Editor
using UnityEngine;
using System.Collections;
using UnityEditor;
public class ClearPrefs : MonoBehaviour {
// otherwise adjusting player settings resolution wont do anything..
// http://answers.unity3d.com/questions/516517/why-doesnt-standalone-build-resolution-settings-af.html
[MenuItem("Edit/Reset Playerprefs")]
@unitycoder
unitycoder / PlanarUVMap.cs
Last active August 29, 2015 14:19
Set UV map to Planar
using UnityEngine;
using System.Collections;
// modified from : http://docs.unity3d.com/ScriptReference/Mesh-uv.html
public class PlanarUVMap : MonoBehaviour {
public bool flipX=false;
void Start()
@unitycoder
unitycoder / AssetStoreBuddy.js
Last active August 29, 2015 14:20
UnityAssetStoreBuddy
// ==UserScript==
// @name AssetStoreBuddy
// @namespace unitycoder.com
// @include https://www.assetstore.unity3d.com/en/#!/search/*
// @version 1
// @grant none
// ==/UserScript==
// currently need to press F5 to run these
@unitycoder
unitycoder / ColorFader.cs
Created May 17, 2015 21:10
Color fade with IEnumerator
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ColorFader : MonoBehaviour
{
public float delay = 2;
void Start () {
StartCoroutine(Fade(delay));
@unitycoder
unitycoder / RotateByDistance.cs
Last active August 29, 2015 14:21
Rotate Sphere By Moved Distance
using UnityEngine;
using System.Collections;
public class RotateByDistance : MonoBehaviour {
public float moveSpeed = 2f;
float radius = 0.5f;
void Start ()
@unitycoder
unitycoder / gist:ddb69aa6199691024a2e
Created May 25, 2015 22:00
Regexp replace all non-numeric characters from string
rawLine = Regex.Replace(rawLine, "[^0-9 ]", ""); // remove non-numeric chars, except space
x - x % gridWidth
// http://stackoverflow.com/questions/1892474/c-sharp-create-snap-to-grid-functionality
@unitycoder
unitycoder / gist:7923ad5ba457caea3451
Last active August 29, 2015 14:25
2 For Loops in 1
// 2 loops in 1 : https://jsfiddle.net/rntasz32/2/
var width=3;
var height=3;
var size = width*height;
var x = 0;
var y = 0;
for (var i = 0; i < size; i++)
{
x = (i / 3) | 0;
@unitycoder
unitycoder / getangle.cs
Created July 20, 2015 22:02
Get 0-360 Angle Between 2D Lines
Vector3 from = p1-pMiddle;
Vector3 to = p2-pMiddle;
float angle = AngleBetween(from, to);
float AngleBetween(Vector3 vector1, Vector3 vector2)
{
var sin = vector1.x * vector2.y - vector2.x * vector1.y;
var cos = vector1.x * vector2.x + vector1.y * vector2.y;