Skip to content

Instantly share code, notes, and snippets.

@ditzel
ditzel / PhysicsHelper.cs
Created January 20, 2019 16:54
Unity Helper for Physic Functions
using UnityEngine;
namespace Ditzelgames
{
public static class PhysicsHelper
{
public static void ApplyForceToReachVelocity(Rigidbody rigidbody, Vector3 velocity, float force = 1, ForceMode mode = ForceMode.Force)
{
if (force == 0 || velocity.magnitude == 0)
@ditzel
ditzel / MeshDestroy.cs
Created August 19, 2019 19:02
MeshDestroy => Put it on a game object with a mesh filter and renderer. Make sure to have read/write enabled on fbx import
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeshDestroy : MonoBehaviour
{
private bool edgeSet = false;
private Vector3 edgeVertex = Vector3.zero;
private Vector2 edgeUV = Vector2.zero;
@ditzel
ditzel / KdTree.cs
Last active April 7, 2024 08:01
k-d Tree
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Profiling;
public class KdTree<T> : IEnumerable<T>, IEnumerable where T : Component
{
protected KdNode _root;
protected KdNode _last;
using UnityEngine;
public class DistanceJoint3D : MonoBehaviour {
public Transform ConnectedRigidbody;
public bool DetermineDistanceOnStart = true;
public float Distance;
public float Spring = 0.1f;
public float Damper = 5f;
using UnityEngine;
using UnityEngine.EventSystems;
public class FixedButton : MonoBehaviour, IPointerUpHandler, IPointerDownHandler
{
[HideInInspector]
public bool Pressed;
// Use this for initialization
void Start()
@ditzel
ditzel / MathParabola.cs
Last active February 19, 2024 02: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;
@ditzel
ditzel / ScrollAndPinch.cs
Created July 22, 2019 17:12
Pinch and Scroll to Move and Zoom in Unity for Mobile Games
/*
Set this on an empty game object positioned at (0,0,0) and attach your active camera.
The script only runs on mobile devices or the remote app.
*/
using UnityEngine;
class ScrollAndPinch : MonoBehaviour
@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;
@ditzel
ditzel / CameraEffects.cs
Last active October 1, 2023 08:12
Camera Shake Effect. Just put in on the camera and call Shake()
using UnityEngine;
namespace DitzeGames.Effects
{
/// <summary>
/// Camera Effects
/// </summary>
public class CameraEffects : MonoBehaviour
{
@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>