Skip to content

Instantly share code, notes, and snippets.

class Timer : IDisposable
{
private readonly string m_Text;
private Stopwatch m_Stopwatch;
public Timer(string text)
{
m_Text = text;
m_Stopwatch = Stopwatch.StartNew();
}
@Cotoff
Cotoff / MouseEventSender
Created April 7, 2014 12:15
This is a Unity3D script that works around colliders intercepting mouse messages when they should not. By using layer mask, this script sends messages to only those objects that need it.
using UnityEngine;
public class MouseEventSender : MonoBehaviour
{
public float RayCastDistance = float.MaxValue;
public LayerMask LayerMask;
public Camera Camera;
public int Button;
private Collider m_LastHit;
@Cotoff
Cotoff / Get 2D object at point
Created May 13, 2015 08:28
A function to find Unity3D object at a given screen point, using 2D colliders
private Collider2D[] m_Hits=new Collider2D[16]; // 16 may not be enough for everyone.
private T GetTargetObject<T>(Vector3 mousePosition) where T:Component
{
var ray = Camera.main.ScreenPointToRay(mousePosition);
var pos = ray.GetPoint(-ray.origin.z/ray.direction.z);
var max = Physics2D.OverlapPointNonAlloc(pos, m_Hits);
for (int ii = 0; ii < max; ii++)
{
var hit = m_Hits[ii];
public class DiscordRunner:MonoBehaviour
{
private const long CLIENT_ID = ...;
private static DiscordRunner s_Instance;
public static void Initialize()
{
#if !DISABLEDISCORD
s_Instance = new GameObject("[Discord runner]").AddComponent<DiscordRunner>();