RapidUnity Scripting Reference
Compatible with: Unity 2.6 and 3.0
The RapidUnity Scripting Reference document has been designed to help new and advanced users alike.
While I have been learning Unity, I have found it time consuming to find answers to seemingly simple questions regarding scripting syntax. I therefore started creating this document as a way to record my findings. Over time the amount of information within the document has grown, and will continue to grow as I learn more and more about Unity.
The problem with scripting is you find a way to do something (for instance change a GameObject’s position or rotation) and then a few months later you will be writing some scripting code and you want to do the same thing, however you cannot remember the exact syntax, or, even worse, find in which script you previously wrote the lines of code.
Now there is a solution to this! In this guide you will find snippets of scripting code that perform a particular action or actions.
This document is not a user guide or training manual, it is more of a quick reference guide!
Table of Contents
Understanding Program Flow Script Event Handlers Script Compilation Order
Accessing/finding GameObjects within a Scene Searching/Recursing entire scene for a GameObject (New v1.2) Getting and Setting a GameObject name Changing a GameObject’s position, rotation and size Creating a GameObject Primitive Accessing Scripts attached to GameObject’s Accessing the Components of a GameObject Adding Components to a GameObject Adding Lights (New v1.2) Creating New Empty GameObject’s Connecting GameObject’s together within the Scene Hierarchy Copying/duplicating GameObject’s
Reading the Keyboard Reading the Mouse Buttons
Reading and Writing Text Files
Loading a Scene at Runtime
Re-using assets, and creating Prefabs
Ways to Pause a Game or Application
Split Screen and Camera Switching
Runtime GUI Scripting Loading Resources Connecting/linking Scenes together via a Menu System
Editor GUI Scripting Getting and Setting the active GameObject EditorGUI Common Dialog Boxes Enabling/Disabling GUI Controls Editor Styles (New v1.3) EditorGUI Foldout Control (New v1.3)
Web/Standalone Player Options (New v1.2)
How to make your own Skyboxes in Unity (New v1.2)
Making use of the Physics Raycast (New v1.3)
Reading Joystick Buttons (New v1.4)
Alternate Project Loading on Startup (New v1.4)
Smarter Coding – Using Functions (New v1.4)
Change skybox in code, actually any of the Edit Render Settings parameters (New v1.4)
Working with SubStrings (New v1.4)
Gizmos (New v1.4)