If you have private fields that are wrapped with a public property but you want the value of those private fields to be saved with your scene you can use the SerializeField attribute.


Did you know with the release of Unity 4 MonoBehaviours can now be inside namespaces! Finally we can better organize our codez!


Did you know you can customize the look of the mouse cursor in your game by calling Cursor.SetCursor?


This is not so much a unity specific tip but more of a C# language tip. if you are trying to port or adapt your game code from one platform to another like for example from XNA over to unity implicit operators may come in handy for automatically casting types and making you code much more readable and easier to port.

Link to MSDN Documentation here

Often times we programmers can fall into bad programming habits and we can forget or overlook language and API features that would otherwise make our lives easier. :P


You can specify the RequireComponent attribute on a class that inherits from MonoBehavior and Unity will add the specified component if it is not already present when you add the script to the game object.

[RequireComponent(typeof(RigidBody))]
public class SomeBehaviorScript : MonoBehaviour
{
}

The unity docs have a great list of recommended performance optimizations available here.


If you are generating meshes procedurally via scripting you can optimize that mesh for drawing by using MeshUtility.Optimize.


You can use editor scripts to specify additional DEFINE directives for conditional compilation by using the EditorUserBuildSettings.activeScriptCompilationDefines property.


If you need your editor script to support drag and drop functionality you can use the methods provided in the DragAndDrop class.


If you need to know when the unity editor is changing play mode states you can hook into the EditorApplication.playmodeStateChanged callback.


Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume