Shortcuts

Code-Completion in Unitron: Alt-Escape

Debug-Break

Debug.Break(); // Obvious!

Enable/disable GameObjects

gameObject.active=false;
gameObject.active=true;

// recursive
gameObject.SetActiveRecursively(false);
gameObject.SetActiveRecursively(true);

Create buttons

function OnGUI() {
	if( GUI.Button( Rect( x, y, w, h ), "Text" ) ) {
		Debug.Print( "Button clicked!" );
	}	
}

Hide/show Game Objects

theGameObject.renderer.enabled = true/false;

Drag objects with the mouse

Source: Unity for Flash Developers

var screenSpace;
var offset;

function OnMouseDown() {
	screenSpace = Camera.main.WorldToScreenPoint(transform.position);
	offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));
}

function OnMouseDrag() {
	var curScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
	var curPosition = Camera.main.ScreenToWorld(curScreenSpace) + offset;
	transform.position = curPosition;
}

Linkdump

Unity/JavaScript Primer

Knowledge Base

Game Development

Personal

PmWiki

pmwiki.org

edit SideBar

Page last modified on July 24, 2009, at 11:22 PM