Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@unitycoder
unitycoder / CreatePlane.cs
Last active December 17, 2015 20:36
CreatePlane, with FlipYZ option
using UnityEngine;
using UnityEditor;
using System.Collections;
// original : http://wiki.unity3d.com/index.php?title=CreatePlane#C.23_-_CreatePlane.cs
public class CreatePlane : ScriptableWizard
{
public enum Orientation
@unitycoder
unitycoder / CustomStructSort
Created March 11, 2015 12:08
Sort custom struct by value
carves.Sort(delegate(Carve a, Carve b) { return a.cumulativeDifference.CompareTo(b.cumulativeDifference); });
/*
// example struct values
public struct Carve
{
public float cumulativeDifference;
public List<int> x;
public List<int> y;
@unitycoder
unitycoder / gist:2be9dea1acde0c210f94
Created March 13, 2015 20:33
Assign texture2D to sprite
// need to create new sprite, cannot assign or convert Texture2D into sprite
Sprite sprite = Sprite.Create (tex, new Rect(0,0,tex.width,tex.height), new Vector2 (0, 0), pixelToUnits);
GetComponent<SpriteRenderer>().sprite = sprite;
http://docs.unity3d.com/ScriptReference/Sprite.Create.html
@unitycoder
unitycoder / gist:058db9730365d806a789
Created March 21, 2015 22:32
SetFocus to UI InputField
public InputField myField;
//..
myField.Select();
myField.ActivateInputField();
@unitycoder
unitycoder / gist:8310e7da082617ea125e
Created March 21, 2015 23:16
Check if GetMouseButtonDown hits UI first
EventSystem eventSystem;
//..
void Start ()
{
GameObject go = GameObject.Find("EventSystem");
if (go==null)
{
Debug.LogError("EventSystem not founded..");
}else{
eventSystem = go.GetComponent<UnityEngine.EventSystems.EventSystem>();
@unitycoder
unitycoder / MeshMelt.shader
Created March 24, 2015 11:51
MeshMelt vertex shader
Shader "Custom/MeshMelt2" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_LavaTex ("LavaTexture", 2D) = "white" {}
_Amount ("Extrusion Amount", Range(-1,1)) = 0.5
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
@unitycoder
unitycoder / Melter.cs
Last active January 23, 2019 06:53
MeshMelter c# script for setting vertex colors
using UnityEngine;
using System.Collections;
public class Melter : MonoBehaviour {
public Transform heatPoint;
public bool restoreColor=false;
void Start () {
var mesh = GetComponent<MeshFilter>().mesh;
@unitycoder
unitycoder / gist:7a90930407f7070cdd75
Created March 24, 2015 21:50
Disable right click menu from webplayer
config.params["disableContextMenu"] = true; // add this line
var u = new UnityObject2(config);
@unitycoder
unitycoder / Stopwatch.cs
Last active February 12, 2023 12:49
Measure time with Stopwatch Timer
var stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
// your function here..
stopwatch.Stop();
//Debug.Log("Timer: " + stopwatch.Elapsed);
Debug.Log("Timer: " + stopwatch.ElapsedMilliseconds);
stopwatch.Reset();
@unitycoder
unitycoder / gist:19304cfd53d412d00b19
Created April 3, 2015 22:45
Get Active Toggle From ToggleGroup
void GetActiveToggle(ToggleGroup group)
{
// get first active toggle (and actually there should be only one in a group)
foreach (var item in group.ActiveToggles())
{
Debug.Log(item.name);
break;
}
}