Let's change LearningCurve to show how to assign a GameObject component using drag and drop:
- Comment out the following line of code, where we used GameObject.Find() to retrieve and assign the Directional Light object to the directionLight variable:
//directionLight = GameObject.Find("Directional Light");
- Select the Main Camera GameObject, drag Directional Light to the Direction Light field in the LearningCurve component, and click on Play:
The Directional Light GameObject is now assigned to the directionLight variable. No code was involved because Unity assigned the variable internally, with no change to the LearningCurve class.
It is important to understand a few things when deciding whether to assign variables using drag and drop or GameObject.Find(). First, the Find() method is marginally slower...