Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
✅
‏‏‎

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / structhistory.js
Created June 22, 2016 03:02
Javascript Struct History Buffer
// we want to keep history of all sent messages
var obj = {
time: (new Date()).getTime(),
text: htmlEntities(message.utf8Data),
author: userName,
color: userColor
};
history.push(obj);
history = history.slice(-100); // keep max 100
@unitycoder
unitycoder / randomizearray.js
Created June 22, 2016 03:05
Randomize Array Order (Javascript)
// Array with some colors
var colors = [ 'red', 'green', 'blue', 'magenta', 'purple', 'plum', 'orange' ];
// ... in random order
colors.sort(function(a,b) { return Math.random() > 0.5; } );
@unitycoder
unitycoder / SliderPingPong.cs
Created June 24, 2016 07:34
SliderPingPong Handle Between Min-Max
using UnityEngine;
using UnityEngine.UI;
public class SliderPingPong : MonoBehaviour
{
public Slider slider;
public float speed = 1;
float pos = 0;
void Update()
@unitycoder
unitycoder / RigidbodyConstraints2DEdit.cs
Created June 25, 2016 10:29
Remove 1 Flag from Current RigidbodyConstraints2D (using bitwise and with bitwise not)
// removes RigidbodyConstraints2D.FreezePositionY from current constraints
rb.constraints = rb.constraints&~RigidbodyConstraints2D.FreezePositionY;
// bitwise math: http://stackoverflow.com/questions/3920307/how-can-i-remove-a-flag-in-c
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
// Hierarchy Icons http://answers.unity3d.com/answers/1113260/view.html
[InitializeOnLoad]
class MyHierarchyIcons
{
static Texture2D texturePanel;
@unitycoder
unitycoder / FakeTubeishLight.shader
Created July 2, 2016 15:57
FakeTubeishLight Shader
Shader "Custom/FakeTubeishLight"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
@unitycoder
unitycoder / SaveMeshInEditor.cs
Created July 7, 2016 02:52
Save Mesh In Editor
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
// Usage: Attach to gameobject, assign target gameobject (from where the mesh is taken), Run, Press savekey
public class SaveMeshInEditor : MonoBehaviour
{
public KeyCode saveKey = KeyCode.F12;
@unitycoder
unitycoder / RandomInsideCircle.cs
Last active January 20, 2019 12:46
Move Sprite Randomly Inside Circle (ant walk)
using UnityEngine;
using System.Collections;
// move transform randomly inside circle
// usage: attach to gameobject, assign sprite to thing field
public class RandomInsideCircle : MonoBehaviour
{
public float speed = 5;
public float radius = 5;
@unitycoder
unitycoder / FollowPosition.cs
Created July 12, 2016 06:45
FollowPosition
using UnityEngine;
public class FollowPosition : MonoBehaviour
{
public Transform target;
void LateUpdate()
{
transform.position = target.position;
}
@unitycoder
unitycoder / Replayer.cs
Created July 17, 2016 07:45
Replay Positions From Array
using UnityEngine;
using System.Collections;
public class Replayer : MonoBehaviour
{
public float delayPerFrame = 0.02f;
public Transform target;
Vector3[] replay;