Skip to content

Instantly share code, notes, and snippets.

@korya
korya / Subfolder to git repo.md
Last active March 25, 2025 09:39
Convert subfolder into Git submodule
@bitbutter
bitbutter / TransparentBackgroundScreenshotRecorder.cs
Last active February 1, 2025 23:54
Rendering screenshots from Unity3d with transparent backgrounds
using UnityEngine;
using System.Collections;
using System.IO;
/*
Usage:
1. Attach this script to your chosen camera's game object.
2. Set that camera's Clear Flags field to Solid Color.
3. Use the inspector to set frameRate and framesToCapture
@CloudyWater
CloudyWater / DashTrailObject.cs
Created August 15, 2016 18:50
Unity 2D Sprite Trail Object
using UnityEngine;
using System.Collections;
public class DashTrailObject : MonoBehaviour
{
public SpriteRenderer mRenderer;
public Color mStartColor, mEndColor;
private float mDisplayTime;
private float mTimeDisplayed;
@mickdekkers
mickdekkers / SnapshotCamera.cs
Last active December 4, 2024 13:46
Take snapshot images of Prefabs and GameObjects in Unity using Render Textures
using UnityEditor;
using UnityEngine;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
// Object rendering code based on Dave Carlile's "Create a GameObject Image Using Render Textures" post
// Link: http://crappycoding.com/2014/12/create-gameobject-image-using-render-textures/
@benloong
benloong / PageViewController.cs
Created January 6, 2017 07:18
Unity UI system PageViewController
using System;
using UnityEngine;
using UnityEngine.EventSystems;
public class PageViewController : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IInitializePotentialDragHandler
{
public enum Direction
{
Horizontal,
Vertical
@ditzel
ditzel / MathParabola.cs
Last active January 5, 2025 08:07
A simple Math class to calculate a point in 2D or 3D space lying on a parabola. And a more complex parabola controller that you can put on an object.
using UnityEngine;
using System;
public class MathParabola
{
public static Vector3 Parabola(Vector3 start, Vector3 end, float height, float t)
{
Func<float, float> f = x => -4 * height * x * x + 4 * height * x;
/*
Copyright (c) 2018 Pete Michaud, github.com/PeteMichaud
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@favoyang
favoyang / BuildAddressables.cs
Last active January 29, 2025 08:24
Build addressable bundles when clicking the build button
/// <summary>
/// The script gives you choice to whether to build addressable bundles when clicking the build button.
/// For custom build script, call PreExport method yourself.
/// For cloud build, put BuildAddressablesProcessor.PreExport as PreExport command.
/// Discussion: https://forum.unity.com/threads/how-to-trigger-build-player-content-when-build-unity-project.689602/
///
/// License: The MIT License https://opensource.org/licenses/MIT
/// </summary>
using UnityEditor;
using UnityEditor.AddressableAssets;
@ruzrobert
ruzrobert / Vibration.cs
Last active February 18, 2025 16:49
Android Vibration for Unity 3D. Supports all API: 1 - 29 (auto detect), Amplitudes, Predefined Effects, both Legacy and >=26 APIs.
using System.Diagnostics.CodeAnalysis;
using UnityEngine;
// Dont forget to add "using RDG;" to the top of your script!
namespace RDG
{
/// <summary>
/// Class for controlling Vibration. Automatically initializes before scene is loaded.
/// </summary>
public static class Vibration
@aras-p
aras-p / DebugNode.hlsl
Created January 3, 2020 10:37
"Print a value" custom function node code for Unity ShaderGraph
// Quick try at doing a "print value" node for Unity ShaderGraph.
// Tested on Unity 2019.2.17 with ShaderGraph 6.9.2.
//
// Use with CustomFunction node, with two inputs:
// - Vector1 Value, the value to display,
// - Vector2 UV, the UVs of area to display at.
// And one output:
// - Vector4 Color, the color.
// Function name is DoDebug.