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 / vector3-dot.cs
Last active May 30, 2018 08:43
Vector3.Dot()
using UnityEngine;
using System.Collections;
public class dottest : MonoBehaviour {
public Transform p1;
public Transform p2;
public Transform p3;
public GUIText guiDOT;
@unitycoder
unitycoder / RotateSpriteTowardsMouse.cs
Last active February 11, 2024 15:42
Rotate sprite towards mouse
// Rotate sprite/object towards mouse
// Reference: http://johnstejskal.com/wp/rotating-objects-and-sprites-in-unity3d-using-cs-c/
// https://forum.unity3d.com/threads/how-to-detect-angle-from-one-object-to-another-in-2d.477510/
// Usage: Attach this script to sprite, use Orthographic camera!
using UnityEngine;
using System.Collections;
public class RotateSpriteTowardsMouse : MonoBehaviour
{
@unitycoder
unitycoder / Pixel2WorldPos
Last active November 14, 2017 07:30
pixel world position (2D quad)
Vector3 pixelPos = new Vector3(x,y,0); // x,y = texture pixel pos
float planeWidth=transform.renderer.bounds.size.x;
float planeHeight=transform.renderer.bounds.size.y;
// convert to 0-1 uv coords
float localX = ((pixelPos.x / texWidth)-0.5f)*planeWidth;
float localY = ((pixelPos.y / texHeight)-0.5f)*planeHeight;
//Vector3 worldPos = transform.TransformPoint(new Vector3(localX,localY, 0));
@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 / Get-values-with-reflection.cs
Last active October 5, 2016 13:59
Get values with reflection
foreach(var prop in terrain.terrainData.GetType().GetProperties())
{
Debug.Log(prop.Name +" : "+ prop.GetValue(terrain.terrainData, null));
}
@unitycoder
unitycoder / gist:9a67e9bd559fb622d0e2
Created January 4, 2015 21:41
LINQ: Pick closest transform from list of gameobjects
using System.Linq;
..
// get list of objects with tag "Player"
GameObject[] gos = GameObject.FindGameObjectsWithTag("Player");
// get closest transform from gos[] array, into target variable, as transform object
var target = gos.OrderBy(go => (transform.position - go.transform.position).sqrMagnitude).First().transform;
@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 / csharp-date-time-formatting.cs
Last active March 3, 2022 21:05
Format Time.time to HH:MM:SS - Date Time - CurrentTime
// example: Debug.Log(FormatTime(Time.time));
string FormatTime(int t)
{
return System.TimeSpan.FromSeconds(t).ToString();
}
// get current datetime formatted
DateTime.Now.ToString("dd/MM/yyyy");