If you need to set the screen resolution of your game via scripting check out Screen.SetResolution.

Did you know that you can manipulate a game objects collider in the scene view by holding down the 'Shift' key. Holding shift will display the colliders control dots. Just drag the dots to adjust the collider!

Unity 101 Tip #11 - Snap to vertex

Published 6/17/2012 by createdbyx in News | Unity
Tags: ,

Hold the 'V' key while the translate tool is active and you can drag an object by it's vertices and snap that vertex to another objects vertex!

Unity 101 Tip #10 - Inspector lock

Published 6/16/2012 by createdbyx in News | Unity
Tags: ,

The inspector window contains a small lock icon in the top right of the window. If you select a game object and click the lock the inspector will be locked to that object and will not change when you select other objects. Click again to disable the lock. This allows you to have multiple instector windows open with locks to different objects.

To allow the user to undo actions that are performed by a custom editor script you can use Undo.RegisterUndo

foreach (var item in Selection.transforms)
    Undo.RegisterUndo(item, "Move " + item.name);
    var pos = item.position;
    pos = new Vector3(activeObject.transform.position.x, pos.y, pos.z);
    item.transform.position = pos;

If you want to take advantage of functionality that is provided my menu commands you can use EditorApplication.ExecuteMenuItem in your editor scripts to execute them.

Are you working on a large project but dislike how many objects you have to weed through in the hierarchy window? You can create editor scripts that change the objects Object.hideFlags property to hide or show the object in the hierarchy window.

var item = Selection.activeGameObject;
if ((item.hideFlags & HideFlags.HideInHierarchy) == HideFlags.HideInHierarchy)
                item.hideFlags = item.hideFlags ^ HideFlags.HideInHierarchy;
                item.active = !item.active;
                item.active = !item.active;

Notice that item.active = !item.active is specified twice. Currently in unity 3.5 you need those 2 lines of code for the game object to hide and show properly in the hierarchy window.

Wondering how to save player preferences across sessions or save settings for an editor script to use? Check out EditorPrefs & PlayerPrefs.

If you are writing custom editors for unity and you need to have a way of editing the tools settings you can have those settings show up in the Unity Preferences Window "Edit -> Preferences...".

Just create a new editor script that has a public class and add the fallowing lines of code ...

// Add preferences section named "cbxTools" to the Preferences Window
    public static void PreferencesGUI()
        // Preferences GUI

If you are creating custom editors for unity but only want the gui for that editor to be drawn in the currently active scene view try this ...    

if (SceneView.mouseOverWindow.GetInstanceID() == SceneView.currentDrawingSceneView.GetInstanceID())

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