This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
/// <summary>DebugText class | |
/// AUTHOR: Beard or Die (more or less) | |
/// BASED ON AND THANKS TO: Video and code by Unity3d.college: https://www.youtube.com/watch?v=uFFexymk3FY | |
/// DATE: 2018-01-11 | |
/// COPYRIGHT: None; even remove this text if you want. | |
/// PURPOSE: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
/// <summary>GhostFreeRoamCamera3D class | |
/// Based on free asset "Ghost Free Roam Camera" by Goosey Gamez | |
/// https://www.assetstore.unity3d.com/en/#!/content/19250 | |
/// That asset has no copyright or license info in its readme and modifications are encouraged | |
/// Modified by: Beard or Die | |
/// Date: 2018-01-12 | |
/// GOAL: A quick camera controller for debugging 3D scenes | |
/// Flexible enough for FPS-style movement (default), or Unity Editor-style movement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
/// <summary>SceneViewCamera3D class | |
/// Based on free asset "Ghost Free Roam Camera" by Goosey Gamez | |
/// https://www.assetstore.unity3d.com/en/#!/content/19250 | |
/// That asset has no copyright or license info in its readme and modifications are encouraged | |
/// Modified by: Beard or Die | |
/// Date: 2018-01-12 | |
/// GOAL: A quick camera controller for debugging 3D scenes | |
/// Flexible enough for FPS-style movement, or Unity Editor-style movement (default) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class My2DExtensions { | |
public static bool IsLeftOf(this GameObject t1, GameObject t2) | |
{ | |
if(t1.transform.position.x < t2.transform.position.x){ return true; } else { return false; }) | |
} | |
public static bool IsRightOf(this GameObject t1, GameObject t2) | |
{ | |
if(t1.transform.position.x < t2.transform.position.x){ return true; } else { return false; } | |
} | |
public static bool IsCenterOf(this GameObject t1, GameObject t2, float wiggleRoom=0f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
/// <summary>DebugTextGameView class | |
/// AUTHOR: Beard or Die | |
/// DATE: 2018-01-12 | |
/// REQUIREMENTS: Add this script onto a GameObject that you want some debug text to | |
/// appear over in Game View. Set up in inspector. You will also need to create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LayerMasks are used often in Unity Technologies' 3D Game Kit to ensure a given interaction is only permitted/triggered by allowed objects. | |
Here are some code snippets they use often in the kit to achieve that check: | |
public LayerMask layers; | |
void OnTriggerEnter(Collider other) | |
{ | |
if (0 != (layers.value & 1 << other.gameObject.layer)) | |
{ | |
// layerMask check is met. Do stuff now. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use a class that does not inherit from MonoBehaviour and has attribute [System.Serializable] | |
// then reference that in a MonoBehaviour class. This results in a dropdown in the Inspector | |
// for the referenced class. | |
// The documentation says to have the NestedClass inherit from System.Object but I've seen no need for that. | |
// For more robust functionality, consider creating a ScriptableObject/template for the Nested Classes, | |
// then reference those. It won't drop down in the inspector the same way, but it affords other benefits. | |
using UnityEngine; | |
public class NestedClassHolder : MonoBehaviour | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you would like to have some UI elements in world space, but always appear on "top" (never obscured by other world objects), here is the setup: | |
- Create a new camera as a child of your main camera, this is your UI camera | |
- Zero out the new camera's transform position, and match its FOV with the parent camera | |
- Set the Layer of this camera to UI | |
- Set Clear Flags to Depth only | |
- Set Culling mask to none then to only the UI layer | |
- On your main camera, set Culling mask to omit the UI layer | |
After doing this, any canvas or UI elements on that canvas set to the UI layer will only use the UI camera to render, and will not be hidden by intersecting world objects. i.e. they will be Always On Top |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using UnityEngine; | |
using UnityEngine.Audio; | |
/// <summary> | |
/// This is a template to create a new Simple Audio Event. | |
/// It supports an array of audio clips, pitch and volume variance, | |
/// and a custom editor that shows a button to preview a random sound | |
/// from the array with the selected pitch and volume variance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
[Serializable] | |
public struct RangedFloat | |
{ | |
public float minValue; | |
public float maxValue; | |
public RangedFloat(float minValue, float maxValue) //constructor | |
{ |
OlderNewer