Skip to content

Instantly share code, notes, and snippets.

View NickDiMucci's full-sized avatar

Nicholas DiMucci NickDiMucci

View GitHub Profile
@NickDiMucci
NickDiMucci / DefaultParamTest.cs
Created April 23, 2014 14:56
Unity default parameter method inside a namespace test. This currently doesn't work as of Unity 4.3.4f1. Multiple exceptions are thrown at runtime.
namespace com.mindshaft.test {
public class DefaultParamTest : MonoBehaviour {
void Update() {
DefaultParamTest();
}
private void DefaultParamTest(int param = 0) {
Debug.Log("param: " + param);
}
}
//Copyright (c) 2014 Tilman Schmidt (@KeyMaster_)
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class UnityBulkReplaceTool : MonoBehaviour
{
public GameObject objectToReplace = null;
public GameObject objectToSpawn = null;
@NickDiMucci
NickDiMucci / 9
Created October 19, 2014 14:04
Resource 9 script to hide input tab from Unity standalone player. To be used with Resource Hacker.
9 DIALOGEX 0, 0, 309, 200
STYLE DS_FIXEDSYS | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "ScreenSel"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
FONT 8, "MS Shell Dlg", FW_NORMAL, FALSE, 1
{
CONTROL "Play!", 1, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 193, 178, 50, 14
CONTROL "Quit", 2, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 252, 178, 50, 14
CONTROL "", -1, BUTTON, BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 7, 3, 295, 108
CONTROL "", 1001, STATIC, SS_BITMAP | SS_CENTERIMAGE | WS_CHILD | WS_VISIBLE, 9, 9, 291, 100
@NickDiMucci
NickDiMucci / 107
Created October 19, 2014 14:06
Resource script 107 to hide input tab from Unity standalone player. To be used with ResourceHacker.
107 DIALOGEX 0, 0, 290, 56
STYLE DS_FIXEDSYS | DS_MODALFRAME | DS_CONTROL | WS_CHILD | WS_SYSMENU
CAPTION ""
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
FONT 8, "MS Shell Dlg", FW_NORMAL, FALSE, 1
{
CONTROL "Screen resolution", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 7, 9, 56, 8
CONTROL "", 1010, COMBOBOX, CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 73, 7, 84, 90
CONTROL "Windowed", 1009, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 169, 7, 49, 10
CONTROL "Graphics quality", -1, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 7, 26, 52, 8
@NickDiMucci
NickDiMucci / minMaxPos
Created May 1, 2015 23:42
Pseudo-code for obtaining the minimum and maximum positions of objects in a 2D space.
List xPositions;
List yPositions;
foreach target {
xPositions.Add(target.x);
yPositions.Add(target.y);
}
maxX = Max(xPositions);
maxY = Max(yPositions);
minX = Min(xPositions);
minY = Min(yPositions);
@NickDiMucci
NickDiMucci / RaycastCollisionDetection.cs
Created November 18, 2014 01:15
Raycast collision detection in Unity from a box collider, with diagonal raycasts from the corners to guard against corner collisions.
using com.mindshaft.overtime.collision;
using UnityEngine;
namespace com.mindshaft.overtime.physics {
public class RaycastCollisionDetection : IEntityCollisionDetection {
private BoxCollider _collider;
private Rect _collisionRect;
private LayerMask _collisionMask;
private LayerMask _playerMask;
private void obtainScreenBounds() {
float cameraToPlayerDistance = Mathf.Abs(Camera.mainCamera.transform.position.z - transform.position.z);
minScreenBounds = Camera.main.ScreenToWorldPoint(new Vector3(0, 0, cameraToPlayerDistance));
maxScreenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, cameraToPlayerDistance));
}
private void checkScreenBoundaries() {
transform.position = new Vector3(
Mathf.Clamp(transform.position.x, (minScreenBounds.x) + 1, (maxScreenBounds.x) - 1),
Mathf.Clamp(transform.position.y, (minScreenBounds.y) + 1, (maxScreenBounds.y) - 1),
@NickDiMucci
NickDiMucci / gist:5020984
Created February 23, 2013 19:28
A poor way to keep a player within the screen bounds in a Unity script.
player.transform.position = new Vector3(
Mathf.Clamp(player.transform.position.x, -8.0f, 8.0f),
Mathf.Clamp(player.transform.position.y, -10.0f, 10.0f),
player.transform.position.z);
@NickDiMucci
NickDiMucci / FlashPlayer.cs
Last active December 14, 2015 03:39
How I'm creating a color flash effect on the player when he gets hit by an object.
public Color[] flashColors;
private float flashLerpDuration = 0.10f;
private float flashInvokeDuration = 0.5f;
void Start() {
// All other initialization code here...
flashColors = new Color[2];
flashColors[0] = Color.magenta;
flashColors[1] = Color.white;
}