The answers above supply more than sufficient information , all I can add for you might be that you should always be carefull in game design to check that when getting a component. It simply may not be there, and during runtime that can cause some serious crash errors. Always encapsulate getting components by stuffing it into testboxes.
try
{
//Get what u need
}
catch (Missing....Exception e)
{
//report the problem code (Can't post the code sorry!)
}
and redundancy checks wont kill you either
if (/*the component I just got*/ != null)
if (!component) //Short version
You can even set a bool to check if something exists but that's even more overkill.
Whenever you handle these exception it's robust programming , and notify the console where the problem occured or what problem , preferably both. Can save you the insane amount of debugging time you will be spending later , as is common in development, it IS the bottleneck of the production line after all.
EDIT: 11/1/2010
This sample checks if there is a main camera of my own code, if not it reports back the place where the problem is to the console and sends the object with it to which this code is attached.
if (OBJECT/VAR == null) ////////Can also do if (!OBJECT/VAR) { ... }
{
//REPORT THE PROBLEM TO CONSOLE
}
else
{
//I FOUND THE CAMERA
}
This sample shows a more simple GetComponent check for a an object, it will assign only if it's not null but will not report anything if it fails ( which probably is not a great idea )
if (GetComponent<CharacterController>() != null)
{
controller = GetComponent<CharacterController>();
}
This sample shows the try catch block
http://msdn.microsoft.com/en-us/library/0yd65esw%28VS.71%29.aspx
Maybe they can explain it better than I can :)
Good luck with your coding, hope this helps, feel free to ask more!