Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / Math3D.cs
Last active June 20, 2023 08:30
Unity Math
static class Math3D
{
private static System.Random rand = new System.Random();
public static float DistanceToLine(Ray ray, Vector3 point)
{
//see:http://answers.unity3d.com/questions/62644/distance-between-a-ray-and-a-point.html
return Vector3.Cross(ray.direction, point - ray.origin).magnitude;
}
@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 / 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
{
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;
@ditzel
ditzel / TouchToShoot.cs
Created May 1, 2018 12:44
Touch to Shoot
using UnityEngine;
public class TouchToShoot : MonoBehaviour {
public Material hitMaterial;
// Use this for initialization
void Start () {
}
@ditzel
ditzel / KdTree.cs
Last active April 29, 2024 21:38
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;
@ditzel
ditzel / HappyCube.cs
Created April 14, 2018 10:02
Mesh from Code
using UnityEngine;
public class HappyCube : MonoBehaviour {
MeshFilter mFilter;
Mesh Mesh;
public float UpDownFactor = 0.1f;
public float UpDownSpeed = 6f;
public float LeftFactor = 0.3f;
@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;