Skip to content

Instantly share code, notes, and snippets.

@ditzel
ditzel / CameraAspectRatioScaler.cs
Last active August 19, 2023 13:19
ResponsiveCamera
using UnityEngine;
/// <summary>
/// Responsive Camera Scaler
/// </summary>
public class CameraAspectRatioScaler : MonoBehaviour {
/// <summary>
/// Reference Resolution like 1920x1080
/// </summary>
@ditzel
ditzel / I18n.cs
Last active June 30, 2023 21:05
Internationalization - See code comments for usage
/*
* Internationalization
*
* Author: Daniel Erdmann
*
* 1. Add this File to you Project
*
* 2. Add the language files to the folder Assets/Resources/I18n. (Filesnames: en.txt, es.txt, pt.txt, de.txt, and so on)
* Format: en.txt: es.txt:
* =============== =================
@ditzel
ditzel / ClickDetector.cs
Last active May 3, 2020 18:34
Detect a OnClick Event in 3D Space on a GameObject
/*
* Detects clicks on game objects
*
* 1. Attach ClickDetector component to a camera or a "game manager" object
* 2. Attach a collider (e.g. BoxCollider) to all objects that should receive a on click event
* 3. Attach a MonoBehaviour to all objects that should receive a on click event registering to the event.
*
* The MonoBehavior should have at least:
*
* public class ClickableGameObject : MonoBehaviour, ClickDetector.ClickDetectorListener
@ditzel
ditzel / RotateObject.cs
Created October 29, 2017 10:08
Rotates an object (rpm can be specifed)
/*
* RotateObject
*
* Author: Daniel Erdmann
*
* 1. Add this File to you Project
*
* 2. Put it on an object
*
*/
@ditzel
ditzel / MathParabola.cs
Last active November 8, 2024 13:48
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;
@ditzel
ditzel / CameraBillboard.cs
Created February 11, 2018 13:53
Rotates an object (e.g. a canvas) to face it towards the camera
/*
* Rotates an object towards the currently active camera
*
* 1. Attach CameraBillboard component to a canvas or a game object
* 2. Specify the offset and you're done
*
**/
using UnityEngine;
using UnityEngine;
using UnityEngine.EventSystems;
public class FixedButton : MonoBehaviour, IPointerUpHandler, IPointerDownHandler
{
[HideInInspector]
public bool Pressed;
// Use this for initialization
void Start()
using UnityEngine;
using System.IO;
public class FileManager
{
/// <summary>
/// Load File
/// </summary>
/// <typeparam name="T">Data Model Type</typeparam>
/// <param name="filename">File Name</param>
@ditzel
ditzel / Platform.cs
Created March 16, 2018 20:13
Moving Platform
using UnityEngine;
/*
* Moving Platform
*
* 1. Attach WayPointPath to an empty game object
* 2. Create empty game object children (these will be handled as waypoints)
* 3. Attach Platform component to a game object and assign the WayPointPath
*
*
**/
@ditzel
ditzel / Paintable.cs
Created April 7, 2018 13:42
Drawing Canvas
using System.Collections;
using System.IO;
using UnityEngine;
public class Paintable : MonoBehaviour {
public GameObject Brush;
public float BrushSize = 0.1f;
public RenderTexture RTexture;