Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@unitycoder
unitycoder / GetAngle.cs
Created December 16, 2015 23:23
Get Angle Between 2 Gameobjects in Degrees (0-360)
using UnityEngine;
using System.Collections;
// helper script for testing angle calculation
// USAGE:
// - Attach this script to objectA and assign objectB as target
// - Then select objectA and move it around ObjectB and you can see angle values in inspector
[ExecuteInEditMode]
public class GetAngle : MonoBehaviour
@unitycoder
unitycoder / MatrixPlayGround.shader
Last active May 9, 2024 08:39
Matrix Playground Shader
// Matrix PlayGround Shader - UnityCoder.com
// References:
// Matrices http://www.codinglabs.net/article_world_view_projection_matrix.aspx
// Rotation: http://www.gamedev.net/topic/610115-solved-rotation-deforming-mesh-opengl-es-20/#entry4859756
Shader "UnityCoder/MatrixPlayground"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
@unitycoder
unitycoder / MidiSound.cs
Last active January 20, 2019 12:45
Play Midi Note with midi-dot-net.dll in Unity
// usage: copy Midi.dll to Assets/Plugins/ folder
// Get it from https://code.google.com/p/midi-dot-net/
using UnityEngine;
using System.Collections;
using Midi; // needs this
public class MidiSound : MonoBehaviour
{
OutputDevice outputDevice;
@unitycoder
unitycoder / MidiPlayer.cs
Created December 23, 2015 23:05
MidiPlayer for Unity (using winmm.dll)
// Midi Player - unitycoder.com
// MidiOutCaps struct from http://svn.tapr.org/repos_sdr_windows/PowerSDR/trunk/Source/Console/midi.cs
// Midi code from http://www.codeguru.com/columns/dotnet/making-music-with-midi-and-c.html
// USAGE: set proper path+filename inside PlayMidi(), attach this scrip to gameobject in scene and hit play!
// Get midi files from internets, like: http://www.vgmusic.com/music/computer/commodore/commodore/
using UnityEngine;
using System.Runtime.InteropServices;
using System.Text;
@unitycoder
unitycoder / LayerMask.cs
Last active July 5, 2024 15:43
LayerMask set initial value to "Default" or "Everything" or multiple layers
public LayerMask layerMask = 1 << 0; // default layer (0)
public LayerMask layerMask2 = ~0; // everything
public LayerMask layerMask2b = -1; // everything
public LayerMask layerMask3 = default;// nothing
public LayerMask layerMask4 = 0;// nothing
public LayerMask layerMask4b; // nothing
public LayerMask layerMask5 = 1 << 5;// layer 5 (UI)
public LayerMask layerMask6 = 1 << 2 | 1 << 5;// Ignore Raycast (Layer 2) AND UI (Layer 5)
public LayerMask layerMask7 = ~(1 << 4 | 1 << 5); // all except layer 4 and 5
public LayerMask layerMask8 = ~(1 << 4); // all except layer 4
@unitycoder
unitycoder / DrawGLLine.cs
Last active May 19, 2023 06:17
DrawLine with GL
using UnityEngine;
public class DrawLine : MonoBehaviour
{
Color lineColor = Color.red;
float distance = 100;
Material lineMaterial;
void CreateLineMaterial()
{
@unitycoder
unitycoder / DrawGizmos.cs
Created December 25, 2015 22:56
Custom DrawGizmos for scripts attached to gameobjects in Editor
using UnityEngine;
using UnityEditor;
public class DrawGizmos
{
[DrawGizmo(GizmoType.Active)] // there are also other options for gizmotypes
static void DrawMyGizmo(MyScript script, GizmoType gizmoType) // set MyScript as your script class/name
{
Debug.DrawRay(script.transform.position, script.transform.up*10, Color.red);
}
@unitycoder
unitycoder / CreateAssetBundles.cs
Last active January 20, 2019 12:45
CreateAssetBundles snippet
using System.IO;
using UnityEditor;
using UnityEngine;
// from http://docs.unity3d.com/Manual/BuildingAssetBundles.html
public class CreateAssetBundles
{
[MenuItem("Assets/Build AssetBundles")]
static void BuildAllAssetBundles()
@unitycoder
unitycoder / RandomAlias.cs
Created December 29, 2015 11:55
c# using alias directive
using UnityEngine;
using System.Collections;
using System;
using Random = UnityEngine.Random; // now random is not conflicted, uses from unityengine
public class RandomAlias : MonoBehaviour
{
void Start ()
{
var r = Random.value;
@unitycoder
unitycoder / SpriteFakeShadow.shader
Created December 31, 2015 08:13
Sprite shader with Shadow (2 pass)
Shader "Sprites/DefaultWithShadow"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
_ShadowOffset ("ShadowOffset", Vector) = (0,-0.1,0,0)
}