void Start() { player = FindObjectOfType <PlayerCommands>(); lightSourceMat = player.GetComponent <Renderer>().sharedMaterials[0]; lightSourceMat.SetFloat("_SpotlightRadius", 0); if (allLights != default(List <LightSource>)) { closestLight = allLights[0]; //CheckProximity, adapted to force to turn on the closest light at the beginning of the game. for (int i = 0; i < allLights.Count; i++) { if (Vector3.Distance(allLights[i].transform.position, player.transform.position) < Vector3.Distance(closestLight.transform.position, player.transform.position)) { closestLight = allLights[i]; } } OnLightSourceActivated(closestLight, lightSourceMat, lightHeight, radius); } }