Scripts Library
Browse, preview, and download ready-to-use C# scripts for your Unity projects.
Health System
Reusable health component with damage, healing, invincibility frames, and events.
public class HealthSystem : MonoBehaviour
{
[SerializeField] private float maxHealth = 100f;
public float HealthPercent => currentHealth / maxHealth;
public void TakeDamage(float damage)
public void Heal(float amount)2D Player Controller
Complete 2D character controller with smooth movement, variable-height jumping, and coyote time.
[RequireComponent(typeof(Rigidbody2D))]
public class PlayerController2D : MonoBehaviour
{
[SerializeField] private float moveSpeed = 8f;
[SerializeField] private float jumpForce = 16f;
[SerializeField] private float coyoteTime = 0.15f;3D Player Controller
First/third person character controller with smooth movement, jumping, and slope handling using C...
[RequireComponent(typeof(CharacterController))]
public class PlayerController3D : MonoBehaviour
{
[SerializeField] private float walkSpeed = 6f;
[SerializeField] private float sprintSpeed = 10f;
[SerializeField] private float jumpHeight = 1.5f;Smooth Camera Follow 2D
Smooth camera follow with offset, dead zone, and look-ahead for 2D games.
public class CameraFollow2D : MonoBehaviour
{
[SerializeField] private Transform target;
[SerializeField] private Vector3 offset = new Vector3(0f, 1f, -10f);
[SerializeField] private float smoothSpeed = 8f;Generic Singleton
Thread-safe, persistent singleton base class for managers like AudioManager, GameManager, etc.
public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
private static T instance;
public static T Instance
{
get { ... }
}First Person Camera
First person mouse look camera with sensitivity, vertical clamp, and cursor lock. Plug into any F...
public class FirstPersonCamera : MonoBehaviour
{
[SerializeField] private float mouseSensitivity = 2f;
[SerializeField] private float minVerticalAngle = -90f;
[SerializeField] private float maxVerticalAngle = 90f;Audio Manager
Complete audio manager with music crossfade, SFX pooling, volume control, and persistence.
public class AudioManager : MonoBehaviour
{
public static AudioManager Instance { get; private set; }
public void PlaySFX(AudioClip clip, float volumeScale = 1f)
public void PlayMusic(AudioClip clip, bool crossfade = true)Object Pool
Generic object pooling system to reduce garbage collection. Perfect for bullets, particles, and e...
public class ObjectPool : MonoBehaviour
{
public static ObjectPool Instance { get; private set; }
public GameObject Spawn(string tag, Vector3 position, Quaternion rotation)
public void Despawn(string tag, GameObject obj)Third Person Camera
Orbit camera with collision detection, zoom, and vertical angle limits. Ideal for action-adventur...
public class ThirdPersonCamera : MonoBehaviour
{
[SerializeField] private Transform target;
[SerializeField] private float defaultDistance = 5f;
[SerializeField] private float rotationSpeed = 5f;Health Bar UI
World-space or screen-space health bar with smooth fill, color gradient, and damage flash. Attach...
public class HealthBarUI : MonoBehaviour
{
[SerializeField] private float smoothSpeed = 5f;
[SerializeField] private Gradient colorGradient;
public void SetHealth(float current, float max)Scene Manager
Async scene loading with loading screen, progress bar, and minimum load time. Clean transitions b...
public class SceneLoader : MonoBehaviour
{
public static SceneLoader Instance { get; private set; }
public void LoadScene(string sceneName)
private IEnumerator LoadSceneAsync(string sceneName)Enemy Chase AI
Enemy AI that detects the player within radius, chases with line-of-sight, and returns to patrol ...
public class EnemyChaseAI : MonoBehaviour
{
[SerializeField] private float detectionRadius = 10f;
[SerializeField] private float fieldOfView = 120f;
[SerializeField] private float chaseSpeed = 5f;Weapon System
ScriptableObject-driven weapon system with melee and ranged attacks, cooldowns, ammo, and damage ...
public class WeaponSystem : MonoBehaviour
{
[SerializeField] private WeaponData currentWeapon;
public void Attack()
public void EquipWeapon(WeaponData weapon)2D Platformer Mechanics
Wall jump, wall slide, dash, and double jump mechanics for 2D platformers. Drop-in extension for ...
[RequireComponent(typeof(Rigidbody2D))]
public class PlatformerMechanics2D : MonoBehaviour
{
[SerializeField] private bool enableWallJump = true;
[SerializeField] private bool enableDoubleJump = true;
[SerializeField] private bool enableDash = true;2D Player Controller Pro
PROAdvanced 2D character controller with wall jump, wall slide, dash, double jump, ledge grab, and m...
[RequireComponent(typeof(Rigidbody2D))]
public class PlayerController2DPro : MonoBehaviour
{
[SerializeField] private float wallSlideSpeed = 2f;
[SerializeField] private float wallJumpForce = 14f;
[SerializeField] private float dashSpeed = 24f;3D Player Controller Pro
PROAdvanced 3D character controller with crouch, slide, ladder climbing, swimming, stamina system, a...
[RequireComponent(typeof(CharacterController))]
public class PlayerController3DPro : MonoBehaviour
{
[SerializeField] private float crouchSpeed = 2.5f;
[SerializeField] private float slideSpeed = 14f;
[SerializeField] private float climbSpeed = 4f;Screen Fader
Simple screen fade-in/fade-out with configurable color and duration. Great for scene transitions.
public class ScreenFader : MonoBehaviour
{
public static ScreenFader Instance { get; private set; }
public Coroutine FadeIn(float duration = -1f)
public Coroutine FadeOut(float duration = -1f)Damage Popup
Floating damage numbers that animate upward and fade out. Supports critical hits, healing, and cu...
public class DamagePopup : MonoBehaviour
{
public static DamagePopup Create(
Vector3 position, float amount,
bool isCritical = false, bool isHeal = false)Camera Shake
Perlin noise camera shake with magnitude, frequency, and duration. Trigger from explosions, impac...
public class CameraShake : MonoBehaviour
{
public static CameraShake Instance { get; private set; }
[SerializeField] private float defaultMagnitude = 0.15f;
[SerializeField] private float frequency = 25f;
public void Shake(float duration, float magnitude)Interaction System
Raycast-based interaction with prompt UI, hold-to-interact option, and IInteractable interface. P...
public interface IInteractable
{
string InteractionPrompt { get; }
void Interact(GameObject interactor);
}Waypoint Patrol AI
Enemy patrol between waypoints with configurable speed, wait times, and patrol patterns (loop, pi...
public class WaypointPatrol : MonoBehaviour
{
public enum PatrolMode { Loop, PingPong, Random }
[SerializeField] private Transform[] waypoints;
[SerializeField] private float moveSpeed = 3f;
[SerializeField] private PatrolMode patrolMode = PatrolMode.Loop;Simple Inventory
Lightweight list-based inventory for prototypes. Add, remove, and check items without UI complexity.
public class SimpleInventory : MonoBehaviour
{
[SerializeField] private int maxSlots = 20;
public int AddItem(string itemId, int quantity = 1)
public int RemoveItem(string itemId, int quantity = 1)JSON Save Utility
File-based JSON save/load utility. Save any serializable class to persistent storage with one met...
public static class JsonSaveUtility
{
public static void Save<T>(T data, string fileName)
public static T Load<T>(string fileName)
public static bool Exists(string fileName)Projectile System
Configurable projectile with speed, damage, lifetime, and optional homing. Integrates with Object...
public class Projectile : MonoBehaviour, IPoolable
{
[SerializeField] private float speed = 20f;
[SerializeField] private float damage = 10f;
[SerializeField] private float lifetime = 5f;
private void OnTriggerEnter(Collider other)Quest System
Lightweight quest tracker with ScriptableObject definitions, objectives, progress tracking, and r...
public class QuestSystem : MonoBehaviour
{
public static QuestSystem Instance { get; private set; }
public bool AcceptQuest(QuestData quest)
public void ReportProgress(string objectiveId, int amount = 1)Input Manager
Clean wrapper around Unity's new Input System with action map switching, rebinding support, and i...
public class InputManager : MonoBehaviour
{
public static InputManager Instance { get; private set; }
public bool WasPressed(string actionName)
public void StartRebind(string actionName)First Person Camera Pro
PROAdvanced FPS camera with head bob, weapon sway, lean, recoil system, and FOV zoom for immersive f...
public class FirstPersonCameraPro : MonoBehaviour
{
[SerializeField] private bool enableHeadBob = true;
[SerializeField] private bool enableLean = true;
[SerializeField] private float zoomFOV = 40f;
public void AddRecoil(float verticalRecoil, float horizontalRecoil)Timer / Countdown
Versatile timer with countdown, stopwatch, and repeating modes. Formatted time display and UnityE...
public class Timer : MonoBehaviour
{
public enum TimerMode { Countdown, Stopwatch, Repeating }
public UnityEvent OnTimerComplete;
public UnityEvent<float> OnTimerTick;
public void StartTimer()NavMesh Click-to-Move
Click-to-move character controller using NavMeshAgent. Click anywhere to navigate, with destinati...
[RequireComponent(typeof(NavMeshAgent))]
public class NavMeshClickToMove : MonoBehaviour
{
private NavMeshAgent agent;
public void MoveTo(Vector3 destination)Pickup / Collectible
Collectible item with bobbing animation, rotation, magnet pull, and event callbacks for coins, he...
public class Collectible : MonoBehaviour
{
[SerializeField] private int value = 1;
[SerializeField] private string itemId = "coin";
private void OnTriggerEnter(Collider other)
private void OnTriggerEnter2D(Collider2D other)Dialogue Trigger
Simple NPC dialogue with sequential messages, typewriter effect, and input to advance. No branchi...
public class DialogueTrigger : MonoBehaviour
{
[SerializeField] private string speakerName = "NPC";
[SerializeField] [TextArea(2, 5)] private string[] messages;
public void StartDialogue()PlayerPrefs Save Helper
Type-safe PlayerPrefs wrapper with support for bool, Vector3, Color, and any serializable object ...
public static class SaveHelper
{
public static void SetObject<T>(string key, T obj)
public static T GetObject<T>(string key, T defaultValue = default)
public static void Save() => PlayerPrefs.Save();Wave Spawner
Wave-based enemy spawner with configurable wave definitions, spawn points, delays, and wave compl...
public class WaveSpawner : MonoBehaviour
{
[System.Serializable]
public class Wave
{
public string waveName = "Wave";
public EnemySpawn[] enemies;
}
private IEnumerator SpawnWave()Top-Down Camera
RTS/strategy camera with WASD panning, edge scrolling, scroll wheel zoom, and optional target fol...
public class TopDownCamera : MonoBehaviour
{
[SerializeField] private float panSpeed = 20f;
[SerializeField] private bool enableEdgeScroll = true;
[SerializeField] private float zoomSpeed = 5f;Tooltip System
Dynamic mouse-following tooltip that auto-positions to stay on screen. Supports rich text and cus...
public class TooltipSystem : MonoBehaviour
{
public static TooltipSystem Instance { get; private set; }
public static void Show(string header, string body = "")
public static void Hide()Minimap System
Render texture minimap with player icon, enemy blips, objective markers, and zoom control.
public class MinimapSystem : MonoBehaviour
{
public static MinimapSystem Instance { get; private set; }
public static void RegisterIcon(Transform target, Color color, float scale = 1f)
public void ZoomIn()
public void ZoomOut()A* Grid Pathfinding
Grid-based A* pathfinding without NavMesh. Supports diagonal movement, weighted nodes, and debug ...
public class AStarPathfinding : MonoBehaviour
{
private class Node
{
public int x, y;
public bool walkable;
public float fCost => gCost + hCost;
}
public List<Vector3> FindPath(Vector3 startPos, Vector3 endPos)Third Person Camera Pro
PROAdvanced orbit camera with lock-on targeting, shoulder swap, cinematic mode, and swappable camera...
public class ThirdPersonCameraPro : MonoBehaviour
{
[SerializeField] private float collisionRadius = 0.25f;
[SerializeField] private bool enableLockOn = true;
[SerializeField] private KeyCode shoulderSwapKey = KeyCode.V;
public void SetProfile(string profileName)Health Bar UI Pro
PROAdvanced health bar with delayed damage indicator, shield overlay, boss mode with phase markers, ...
public class HealthBarUIPro : MonoBehaviour
{
[SerializeField] private Image delayedFillImage;
[SerializeField] private bool showSegments;
[SerializeField] private int segmentCount = 5;
public void SetHealth(float current, float max)Weapon System Pro
PROAdvanced ScriptableObject weapon system with combo chains, weapon switching, damage types, critic...
public class WeaponSystemPro : MonoBehaviour
{
[SerializeField] private List<WeaponDataPro> weaponInventory;
public void EquipWeapon(int index)
public void Reload()
public bool AddModifier(WeaponModifier mod)Swipe Input Controller
Detects touch swipes in four directions with configurable thresholds and dead zones. Fires UnityE...
public enum SwipeDirection { None, Up, Down, Left, Right }
[SerializeField] private float minSwipeDistance = 50f;
public UnityEvent onSwipeUp;Tap Input Handler
Handles single tap, double tap, and long press gestures with configurable timing. Provides tap po...
public UnityEvent<Vector2> onSingleTap;
public UnityEvent<Vector2> onDoubleTap;
public UnityEvent<Vector2> onLongPress;Touch Joystick
Virtual on-screen joystick for mobile touch input with dynamic or fixed positioning. Outputs norm...
public class TouchJoystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
{
public Vector2 InputDirection { get; private set; }
[SerializeField] private float handleRange = 50f;Endless Runner Controller
Complete endless runner character controller with auto-forward movement, lane switching, jump and...
[RequireComponent(typeof(CharacterController))]
public class EndlessRunnerController : MonoBehaviour
{
[SerializeField] private float laneWidth = 2.5f;
[SerializeField] private float jumpForce = 10f;Score Manager
Complete score management system with high score persistence, combo multipliers with decay, and s...
public static ScoreManager Instance { get; private set; }
public void AddScore(int points)
{
int earnedPoints = points * ComboMultiplier;Day/Night Cycle
Configurable day/night cycle with directional light rotation, color gradient, and time-of-day eve...
public class DayNightCycle : MonoBehaviour
{
[SerializeField] [Range(0f, 24f)] private float timeOfDay = 12f;
[SerializeField] private Light directionalLight;
[SerializeField] private Gradient sunColor;Procedural Dungeon Generator
BSP-based dungeon generator that creates random room layouts with corridors, doors, and spawn poi...
public class DungeonGenerator : MonoBehaviour
{
[SerializeField] private int minRoomSize = 6;
[SerializeField] private int maxRoomSize = 15;
[SerializeField] private int corridorWidth = 2;
public void Generate()Waypoint Patrol AI Pro
PROAdvanced patrol AI with NavMesh pathfinding, player detection with awareness meter, alert states,...
[RequireComponent(typeof(NavMeshAgent))]
public class WaypointPatrolPro : MonoBehaviour
{
public enum AIState { Patrol, Alert, Investigate, Return }
[SerializeField] private float awarenessRate = 1.5f;
[SerializeField] private float alertCallRange = 15f;Touch Button
Mobile-friendly UI button with press, release, and hold events plus visual feedback. Includes con...
public class TouchButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public UnityEvent onPressed;
[SerializeField] private float pressedScale = 0.9f;Pinch-to-Zoom Camera
Smooth pinch-to-zoom camera control for mobile devices supporting both orthographic and perspecti...
public class PinchToZoomCamera : MonoBehaviour
{
[SerializeField] private float zoomSpeed = 0.5f;
float currentDistance = Vector2.Distance(touch0.position, touch1.position);Stack Mechanic
Tap-to-place stacking game mechanic where a moving block must be stopped to align with the previo...
public class StackMechanic : MonoBehaviour
{
[SerializeField] private float perfectThreshold = 0.05f;
float overhang = currentPosX - previousBlockPosX;Idle Income Generator
Passive income system for idle/clicker games with offline earnings calculation, upgrade scaling, ...
public double IncomePerSecond => CalculateIncome();
public static string FormatNumber(double number)
{
if (number >= 1e12) return (number / 1e12).ToString("F1") + "T";Mobile Safe Area Handler
Automatically adjusts UI RectTransform to respect device safe areas on notched phones and tablets...
[RequireComponent(typeof(RectTransform))]
public class MobileSafeArea : MonoBehaviour
{
Rect safeArea = Screen.safeArea;
anchorMin.x /= Screen.width;Gyroscope Camera Controller
Controls camera rotation using the device gyroscope sensor with smoothing and sensitivity setting...
public class GyroscopeCameraController : MonoBehaviour
{
[SerializeField] private float sensitivity = 1f;
Quaternion convertedRotation = ConvertGyroRotation(rawGyro);Mobile Responsive UI Scaler
Dynamically adjusts UI scaling based on device aspect ratio, DPI, and orientation. Works with Uni...
[RequireComponent(typeof(CanvasScaler))]
public class MobileResponsiveScaler : MonoBehaviour
{
[SerializeField] private Vector2 referenceResolution = new Vector2(1080, 1920);
canvasScaler.matchWidthOrHeight = match;