Unity Tips from Recorded Video Training Sessions
Tutorial
Beginner
3 Hours55 Mins
Overview
Overview
Summary
In this session, we will present an assortment of tips and tricks to use while working with Unity. These tips and tricks could make our experience in Unity better, faster, stronger or they could just keep us amused. We could simply be reminded of the obvious or we could be presented with something we've never heard of, thought of or imagined. Like entering a flea market or wild bazaar, we will hunt around and try to find something for everyone, even if everything we present isn't useful to all.
Topics we'll cover
Language
English
Recommended Unity Versions
4.5
Tutorial
Unity Tips from Recorded Video Training Sessions
1.
Unity Tips & Tricks 2
In this session, we will present an assortment of tips and tricks to use while working with Unity. These tips and tricks could make our experience in Unity better, faster, stronger or they could just keep us amused. We could simply be reminded of the obvious or we could be presented with something we've never heard of, thought of or imagined. Like entering a flea market or wild bazaar, we will hunt around and try to find something for everyone, even if everything we present isn't useful to all. Tutor: Adam Buckner

2.
Unity Tips & Tricks 3
In this session, we will present an assortment of tips and tricks to use while working with Unity. These tips and tricks could make our experience in Unity better, faster, stronger or they could just keep us amused. We could simply be reminded of the obvious or we could be presented with something we've never heard of, thought of or imagined. Like entering a flea market or wild bazaar, we will hunt around and try to find something for everyone, even if everything we present isn't useful to all. Tutor: Adam Buckner
In this specific session we covered Inspector Tips, including Component Tools, the Documentation Quick Reference, the Context Menu, Reset Functions, Menu Item Attributes, a script to Align with Ground, additional useful attributes and an open Q&A session.

AlignWithGround

using UnityEngine; using UnityEditor; using System.Collections public class AlignWithGround : MonoBehaviour { [MenuItem ("Tools/Transform Tools/Align with ground %t")] static void AlignWithGround () { Transform [] transforms = Selection.transforms; foreach (Transform myTransform in transforms) { RaycastHit hit; if (Physics.Raycast (myTransform.position, -Vector3.up, out hit)) { Vector3 targetPosition = hit.point; if (myTransform.gameObject.GetComponent<MeshFilter>() != null) { Bounds bounds = myTransform.gameObject.GetComponent<MeshFilter>().sharedMesh.bounds; targetPosition.y += bounds.extents.y; } myTransform.position = targetPosition; Vector3 targetRotation = new Vector3 (hit.normal.x, myTransform.eulerAngles.y, hit.normal.z); myTransform.eulerAngles = targetRotation; } } } }

Demo Script

using UnityEngine; using UnityEditor; using System.Collections; [System.Serializable] public class MyClass { public int myOtherInt; public float myOtherFloat; } [ExecuteInEditMode] public class DemoScript : MonoBehaviour { [ContextMenuItem ("Set my string","SetString")] public string myString; [HideInInspector] public int myInt; [Range (2,5)] public float myFloat; public MyClass myClass; [SerializeField] private float myPrivateFloat; [ContextMenu ("Item added to Context Menu")] void TestContextMenu () { Debug.Log ("Context Menu"); } void SetString () { myString = "Olive Oyl"; } [MenuItem ("CONTEXT/Rigidbody/Double Mass")] static void DoubleMass (MenuCommand command) { Rigidbody rb = (Rigidbody) command.context; rb.mass = rb.mass * 2; } void Reset () { myInt = 6; myFloat = 7.7f; } [MenuItem ("Tools/3D/Set Mass")] static void SetMass () { Rigidbody rb = Selection.activeTransform.GetComponent<Rigidbody>(); rb.mass = 100.0f; } }

3.
Unity Tips & Tricks 4
In this session, we will present an assortment of tips and tricks to use while working with Unity. These tips and tricks could make our experience in Unity better, faster, stronger or they could just keep us amused. We could simply be reminded of the obvious or we could be presented with something we've never heard of, thought of or imagined. Like entering a flea market or wild bazaar, we will hunt around and try to find something for everyone, even if everything we present isn't useful to all. Tutor: Adam Buckner
In this specific session we covered Mathf, including Lerp, MoveTowards, Perlin Noise, followed by aligning GameObjects, including Vertex and Surface Snapping and more, with an open Q&A session at the end.

4.
Unity Tips and Tricks Grab Bag
Who doesn't like #unitytips? In this session we will look at a bunch of different tips and tricks that you may not have known about. Topics include how to: Visualizing in the scene view with editor extensions, modularizing assets, and using particles for performance gain. We are literally cramming as much stuff into an hour session as we can, so who knows how much we'll cover! Let's find out! Trainer: Mike Geig
Scripts for the navigation editor extensions

CharacterNavigation

using UnityEngine; public class CharacterNavigation : MonoBehaviour { public Transform target; NavMeshAgent agent; void Awake() { agent = GetComponent<NavMeshAgent>(); } void Update () { agent.SetDestination(target.position); agent.Stop(); } }

CharacterNavigationEditor

using UnityEngine; using UnityEditor; [CustomEditor(typeof(CharacterNavigation))] public class CharacterNavigationEditor : Editor { static bool visualizePath = false; public override void OnInspectorGUI() { DrawDefaultInspector(); visualizePath = EditorGUILayout.Toggle("Visualize Path", visualizePath); } [DrawGizmo(GizmoType.Selected | GizmoType.NonSelected)] static void DrawLinesForNavAgent(NavMeshAgent agent, GizmoType gizmoType) { if (!visualizePath || agent.path == null) return; Gizmos.color = Color.red; Vector3[] points = agent.path.corners; for (int i = 0; i < points.Length - 1; i++) { Gizmos.DrawLine(points[i], points[i + 1]); } } }
Scripts for the particle optimizations

EmitterScript

using UnityEngine; using System.Collections; public class EmitterScript : MonoBehaviour { public float rate = 20f; public int maxCoins = 100; public GameObject coin; Rigidbody2D[] coins; int index; float amntPerUpdate; void Start () { coins = new Rigidbody2D[maxCoins]; for (int i = 0; i < maxCoins; i++) { coins[i] = (Instantiate(coin) as GameObject).GetComponent<Rigidbody2D>(); coins[i].gameObject.SetActive(false); } amntPerUpdate = rate * .02f; index = 0; } void FixedUpdate() { for (int i = 0; i < amntPerUpdate; i++) { coins[index].gameObject.SetActive(false); coins[index].transform.position = transform.position; coins[index].transform.rotation = Quaternion.identity; coins[index].gameObject.SetActive(true); Vector3 velocity = new Vector3(Random.Range(-2f, 2f), 10f, 0f); coins[index].velocity = velocity; if (++index >= maxCoins) index = 0; } } }

ParticleCoinScript

using UnityEngine; public class ParticleCoinScript : MonoBehaviour { public ParticleSystem coinSystem; public Transform playerPosition; public float floorHeight = 0f; int maxParticles; ParticleSystem.Particle[] coins; void Start() { maxParticles = coinSystem.maxParticles; coins = new ParticleSystem.Particle[maxParticles]; } void Update() { coinSystem.GetParticles(coins); for (int i = 0; i < coins.Length; i++) { //Bounce if (coins[i].position.y < floorHeight) { if (coins[i].velocity.y < 0) coins[i].velocity = new Vector3(coins[i].velocity.x, 5, coins[i].velocity.z); else coins[i].position = new Vector3(coins[i].position.x, floorHeight, coins[i].position.z); } //Collect by player float distance = Vector3.Distance(coins[i].position, playerPosition.position); if (Mathf.Abs(distance) <= 1.5f) coins[i].lifetime = 0f; } coinSystem.SetParticles(coins, maxParticles); } }