This file contains hidden or 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
[InlineButton("AutoName", "Auto")] | |
public new string name; | |
public void AutoName() | |
{ | |
#if UNITY_EDITOR | |
string assetPath = UnityEditor.AssetDatabase.GetAssetPath(GetInstanceID()); | |
name = System.IO.Path.GetFileNameWithoutExtension(assetPath); | |
#endif | |
} |
This file contains hidden or 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
// this is not a full class, just a code snippet showing the relevant method to convert a Color object | |
// to an RGB hex value so it can be used in a text field | |
public Color playerColor; | |
public Text playerTextField; | |
playerTextField.text = "<color=#" + ColorUtility.ToHtmlStringRGB(playerColor) + ">PLAYER</color>"; |
This file contains hidden or 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
// put this line in EVERY .cs file that gets that annoying error about a variable always having default value | |
#pragma warning disable 0649 |
This file contains hidden or 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 UNITY_EDITOR | |
using System.Collections; | |
using UnityEditor; | |
using UnityEngine; | |
[ExecuteInEditMode] | |
public class SimulateGravity : MonoBehaviour | |
{ | |
public bool simulate = false; | |
public bool remove = false; |
This file contains hidden or 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; | |
[RequireComponent(typeof(AudioSource))] | |
[RequireComponent(typeof(Collider))] | |
public class CollisionAudio : MonoBehaviour | |
{ | |
[SerializeField] private AudioClip collideSoft; | |
[SerializeField] private AudioClip collideHard; |
This file contains hidden or 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; | |
public class MinMaxRangeAttribute : Attribute | |
{ | |
public MinMaxRangeAttribute(float min, float max) | |
{ | |
Min = min; | |
Max = max; | |
} |
This file contains hidden or 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 | |
{ |
This file contains hidden or 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 hidden or 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 |