Skip to content

Instantly share code, notes, and snippets.

View Keldrik's full-sized avatar

Thomas Wiegold Keldrik

View GitHub Profile
@Keldrik
Keldrik / UnityParticleAutoDestroy.cs
Created February 17, 2015 16:40
Unity Script: Destroy non-looping particle objects automatically when they are no longer alive
using UnityEngine;
using System.Collections;
public class ParticleAutoDestroy : MonoBehaviour
{
private ParticleSystem ps;
void Start()
{
ps = GetComponent<ParticleSystem>();
@Keldrik
Keldrik / UnityCameraFollowObject.cs
Last active March 9, 2023 22:55
Unity Script: Smooth Follow and LookAt Object Behavior for Camera
using UnityEngine;
using System.Collections;
public class CameraFollowObject : MonoBehaviour
{
public Transform TargetObject;
public float MoveSmoothTime = 0.3F;
public float RotationSpeed = 6f;
public Vector3 Offset = new Vector3(0f, 15f, 0f);
@Keldrik
Keldrik / UnityBewegungMitPfeiltasten.cs
Last active March 9, 2023 22:55
Unity Einfache Bewegung Beispiel Script
using UnityEngine;
using System.Collections;
public class Bewegen : MonoBehaviour
{
// public member eines Scripts können bequem
// im Unity Editor gesetzt und auch während
// das Spiel getestet wird verändert werden.
@Keldrik
Keldrik / UnityCheckMouseHitObjectByTag.cs
Created May 21, 2014 15:03
Unity: Check if Mouse hits gameobject with specified tag
public bool CheckMouseHitObjectByTag(Camera cam, string tag)
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if (tag == hit.collider.tag)
{
return true;
}
@Keldrik
Keldrik / UnityMouseToWorldPoint.cs
Last active August 29, 2015 14:01
Unity: Convert Mouse Position to Point in World Space
public Vector3 MouseToWorldPoint(Camera cam, float distance)
{
var m = Input.mousePosition;
m.z = distance;
return cam.ScreenToWorldPoint(m);
}