Skip to content

Instantly share code, notes, and snippets.

@dnkm
dnkm / Constant
Created March 31, 2015 19:26
Unity Mathf.lerp
// constant movement
void Update() {
transform.position = Vector3.Lerp(pos1.position, pos2.position, speed * timer);
if (destination == pos1) {
timer = Mathf.Clamp(timer = Time.deltaTime, 0.0f, 1.0f/speed);
} else {
timer = Mathf.Clamp(timer + Time.deltaTime, 0.0f, 1.0f/speed);
}
}
@dnkm
dnkm / SnapToGrid
Created March 24, 2015 19:09
Grid Snapping
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class SnapToGrid : MonoBehaviour {
public float cell_size = 1f; // = larghezza/altezza delle celle
private float x, y, z;
void Start() {
@dnkm
dnkm / MainCameraBorder
Last active August 29, 2015 14:17
Gizmo Exampls
using UnityEngine;
using System.Collections;
public class Gizmo : MonoBehaviour {
public bool ShowMainCameraBorder;
void OnDrawGizmos() {
if (ShowMainCameraBorder) {
float z = GetComponent<Camera>().nearClipPlane;
Vector3 max = GetComponent<Camera>().ViewportToWorldPoint(new Vector3(1, 1, z));