Skip to content

Instantly share code, notes, and snippets.

Dominik Haas DomDomHaas

Block or report user

Report or block DomDomHaas

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@DomDomHaas
DomDomHaas / gist:e31156e8c67dbcad8637
Last active Aug 29, 2015
Unity RayCast from clicking
View gist:e31156e8c67dbcad8637
Vector3 clickPos = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 0);
Ray camRay = Camera.main.ScreenPointToRay (clickPos);
RaycastHit hit;
if (Physics.Raycast (camRay.origin, camRay.direction,
out hit, rayLength, fieldMask)) {
// do awesome stuff here
}
@DomDomHaas
DomDomHaas / gist:ea3c2b8f5cdb0c66ee91
Created Aug 1, 2014
get the average RGB form a texture
View gist:ea3c2b8f5cdb0c66ee91
private Color getAverageRGB (Texture2D tex)
{
Color[] allPixels = tex.GetPixels (0, 0, tex.width, tex.height);
float r = 0;
float g = 0;
float b = 0;
int interationSteps = 1;
for (int i = 0; i < allPixels.Length; i += interationSteps) {
@DomDomHaas
DomDomHaas / GetSpriteFromPath
Last active Aug 29, 2015
get a Sprite from any path using unity WWW Class (and get the mesh to add it on a meshCollider)
View GetSpriteFromPath
/// <summary>
/// Gets a sprite from any path
/// </summary>
/// <returns>The sprite from WW.</returns>
/// <param name="fullPath">Full path.</param>
public static Sprite getSpriteFromWWW (string fullPath, bool packTight = false)
{
fullPath = "file:///" + fullPath;
WWW wwwLoader = new WWW (fullPath);
//Debug.Log ("loading texture " + fullPath + " via www, loaded: " + www);
@DomDomHaas
DomDomHaas / gist:bf1094ca7d0314165966
Created Jun 7, 2014
Unity Robust Data Validation
View gist:bf1094ca7d0314165966
using UnityEngine;
using System.Collections;
// script according to the talk at unit2013 : https://www.youtube.com/watch?v=Ozc_hXzp_KU
public class ValidateMe05 : MonoBehaviour
{
private const float minFloatValue = 0.1f;
private const float maxFloatValue = 15f;
@DomDomHaas
DomDomHaas / gist:f73cb01c03c9ee23bf41
Last active Aug 29, 2015
AnimationEvents in Unity
View gist:f73cb01c03c9ee23bf41
using UnityEngine;
using System.Collections;
public class EnemyAnimationControl : MonoBehaviour
{
private Animator animControl;
private GameObject attackCollider;
private GameObject checkCollider;
@DomDomHaas
DomDomHaas / gist:c61d08bba0d75d84a4da
Last active Aug 29, 2015
MasterAudio get PlayListSource change pitch
View gist:c61d08bba0d75d84a4da
private AudioSource playlistSource;
playlistCont = PlayListController.Instance;
playlistSource = playlistCont.CurrentPlaylistSource;
if (usePitchAddtion) {
checkAddPitch ();
} else {
checkPitchChange ();
@DomDomHaas
DomDomHaas / gist:a1cfc0ca25d6751e5f56
Last active Aug 29, 2015
Coroutines for (gamepad) vibration patterns using iTween to get the linear transition
View gist:a1cfc0ca25d6751e5f56
public IEnumerator ImpactVibration (float enemyDirection)
{
float vibTime = 0.5f;
float impVibStart = 0.1f;
float impVibStrength = 0.35f;
doVibrate = true;
StartCoroutine (DoVibrate ());
if (enemyDirection > 0) {
StartCoroutine (setVibrate (0, vibTime, impVibStart, impVibStrength, "setLeftVibrate"));
@DomDomHaas
DomDomHaas / gist:f0a619b7fc0e6fc805a9
Created May 9, 2014
Spectrum Analyzer converted from c++ to c#
View gist:f0a619b7fc0e6fc805a9
using System;
/*
* main.cpp - spectrum_analyzer
* https://bitbucket.org/andor44/spectrum_analyzer
*
* Copyright (c) 2011 TÖRÖK Attila <torokati44@gmail.com>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@DomDomHaas
DomDomHaas / weaponSwitch
Last active Aug 29, 2015
Unity Weapon switch with Bone Connection
View weaponSwitch
// copy & past from see: https://www.youtube.com/watch?v=VH0ZfEv_ouc
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
//attach 2 weapon prefabs to weapon1 and weapon2
//attach a bone Transform (head, foot, hand etc..) from your
@DomDomHaas
DomDomHaas / Unity3D isWallInFront ()
Last active Aug 29, 2015
Untiy raycasting in to ensure a character doesn't move inside a wall
View Unity3D isWallInFront ()
if (!isWallInFront (moveDirection)) {
this.rigidbody.MovePosition (this.rigidbody.position + this.transform.right * xAxis * xFacing);
}
private bool isWallInFront (Vector3 direction)
{
if (UnityShortcuts.castRay (this.rigidbody.position, this.transform.right, rayCastLength, moveAlignLayer)) {
//Debug.Log ("got wall hit!");
You can’t perform that action at this time.