Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@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 / BitShift.txt
Last active April 15, 2023 19:03
Bitshift CheatSheet Bitconverter BitWise
// MULTIPLY
a=1
a << 1 == a*2 [ a=2 ]
a << 2 == a*4 [ a=4 ]
a << 3 == a*8 [ a=8 ]
1 << 1 == 1*2 [ a=2 ]
1 << 2 == 1*4 [ a=4 ]
1 << 3 == 1*8 [ a=8 ]
@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 / PackTest.cs
Created May 22, 2015 17:00
Pack 3-Floats [0-1] to 1-Float
using UnityEngine;
using System.Collections;
// source: http://diaryofagraphicsprogrammer.blogspot.fi/2009/10/bitmasks-packing-data-into-fp-render.html
public class PackTest : MonoBehaviour {
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
@unitycoder
unitycoder / sort array
Last active October 26, 2019 19:53
Sort System.Array of custom Struct with CompareTo
Array.Sort(tiles, new Comparison<YourThing>((a, b) => b.x.CompareTo(a.x)));
@unitycoder
unitycoder / DollyZoom.cs
Last active April 11, 2019 15:24
DollyZoom
using UnityEngine;
using System.Collections;
// http://en.wikipedia.org/wiki/Dolly_zoom
public class DollyZoom : MonoBehaviour
{
public Transform target;
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;