Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@unitycoder
unitycoder / curl.md
Last active September 19, 2022 10:46
curl from commandline

curl post from (git) bash, with spoofed ip

$ curl --header "X-Forwarded-For: #.#.#.#" 'http://targetpost.url' --data 'your=1&data=2&here=ok'

tip: use copy cURL

curl HTTP cheat sheet

HTML version here

Markdown attempt

@unitycoder
unitycoder / ScreenEdge.cs
Last active December 30, 2024 02:04
Create Ortho Screen EdgeColliders2D - Collider Edge
// perspective camera, get far clip plane edges in world space (z is set to 0)
var bottomLeft = (Vector2)cam.ScreenToWorldPoint(new Vector3(0, 0, cam.farClipPlane));
var topLeft = (Vector2)cam.ScreenToWorldPoint(new Vector3(0, cam.pixelHeight, cam.farClipPlane));
var topRight = (Vector2)cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth, cam.pixelHeight, cam.farClipPlane));
var bottomRight = (Vector2)cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth, 0, cam.farClipPlane));
Debug.DrawLine(bottomLeft, topLeft, Color.red, 33);
Debug.DrawLine(topLeft, topRight, Color.green, 33);
Debug.DrawLine(topRight, bottomRight, Color.blue, 33);
Debug.DrawLine(bottomRight, bottomLeft, Color.magenta, 33);
@unitycoder
unitycoder / timer.cs
Created August 3, 2015 17:09
Timer with ms
void Update () {
Debug.Log(FormatTime(Time.time));
}
string FormatTime(float t)
{
var time = System.TimeSpan.FromSeconds(t);
return string.Format("{0:D2}:{1:D2}:{2:D3}", time.Minutes, time.Seconds, time.Milliseconds);
}
@unitycoder
unitycoder / InitButton.cs
Last active December 13, 2018 15:34
Init UI button as selected
using UnityEngine;
using UnityEngine.UI;
// makes button selected at Start (to force Highlighted color on it)
// this is required to allow pressing Fire / Submit key to press button (without having to select button first)
public class InitButton : MonoBehaviour
{
void Start ()
{
@unitycoder
unitycoder / LudumDareKeysToVote.js
Last active April 5, 2016 04:04
LudumDare Theme Slaughter with arrowkeys & GreaseMonkey Firefox plugin
// ==UserScript==
// @name LudumDareThemeSlaughterKeyboard
// @namespace unitycoder.com
// @description use arrowkeys to vote
// @include http://ludumdare.com/theme/*
// @include http://www.ludumdare.com/theme/*
// @version 1.3
// @grant none
// ==/UserScript==
@unitycoder
unitycoder / SetSortingOrderAndLayer.cs
Created August 20, 2015 16:58
SetSortingOrderAndLayer
using UnityEngine;
public class SetSortingOrderAndLayer : MonoBehaviour {
public int sortingOrder = 0;
public string layerName = "Default";
void Awake()
{
GetComponent<Renderer>().sortingOrder = sortingOrder;
@unitycoder
unitycoder / threshold.shader
Created August 22, 2015 18:22
Threshold color values in Shader
// https://github.com/genekogan/Processing-Shader-Examples/blob/master/TextureShaders/data/threshold.glsl
float bright = 0.33333 * (color.r + color.g + color.b);
float b = lerp(0.0, 1.0, step(0.1, bright));
@unitycoder
unitycoder / UnityAnswers2015.css
Last active August 29, 2015 14:28
Unity Answers Custom CSS
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("answers.unity3d.com")
{
/* http://unitycoder.com/blog/2015/08/25/unity-answers-custom-css-style/ */
/* --------------- page --------------- */
/* page padding */
.main{
padding: 0px !important;
@unitycoder
unitycoder / children.cs
Last active June 2, 2022 10:31
Loop All Transform Children (not deep scan)
// loops only first level
foreach (Transform child in transform)
{
Debug.Log(child.name);
}
// loop all recursive https://forum.unity.com/threads/loop-through-all-children.53473/#post-340519
void TraverseHierarchy(Transform root)
{
for (Transform child in root) {
@unitycoder
unitycoder / publicstaticpropery
Created September 2, 2015 20:45
Public Static Get Set property
static int _myNumber;
public static int MyNumber
{
get
{
// add custom logic here when value is queried
return _myNumber;
}
set
{