Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@unitycoder
unitycoder / gist:3c51d415332e162257cd
Last active August 29, 2015 14:02
Unity3D New Forums Custom Css Style
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("forum.unity3d.com") {
/*
Unity3D Forums Style (to make the new forums bit more easier to read..)
Stylish plugin for Firefox : https://addons.mozilla.org/en-US/firefox/addon/stylish/
WORK-IN-PROGRESS (Feel Free To Fork/Suggest new css)
*/
@unitycoder
unitycoder / OneLinePause.cs
Last active August 29, 2015 14:10
PauseToggle with Time.timeScale
using UnityEngine;
using System.Collections;
public class PauseMode : MonoBehaviour
{
void Update ()
{
if (Input.GetKeyDown ("p")) Time.timeScale = 1-Time.timeScale;
}
}
@unitycoder
unitycoder / gist:7212cc1d6912feb64b83
Created December 5, 2014 23:21
IEnumerator Wait
// http://unitypatterns.com/scripting-with-coroutines/
IEnumerator Wait(float duration)
{
for (float timer = 0; timer < duration; timer += Time.deltaTime)
{
yield return 0;
}
}
@unitycoder
unitycoder / gist:367a900a185fc9361db4
Created February 22, 2015 16:52
Vector2i with ToString
using System;
public struct Vector2i
{
private int X;
private int Y;
private int x
{
set { X = value; }
@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 / 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 / GetSliderValue
Last active August 29, 2015 14:18
Get UI Slider Value
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GetSliderValue : MonoBehaviour {
public YourScript yourScript;
void Awake ()
{