Hi everyone, I’ve been looking to get started in Unity ever since Unity 5 was announced, before then I only really had, for lack of a better term, “experience”, with UDK through my University course.
I’m trying to start out simple with scripting. I love that Unity uses C# as that’s what I’ve been learning for the past 2 years at uni so I figured I’d get something going pretty quickly.
I have the following script:
using UnityEngine;
using System.Collections;
public class Fade : MonoBehaviour {
private Light fadeLight;
private bool direction;
// Use this for initialization
void Start () {
fadeLight = GetComponent<Light>();
direction = true;
}
// Update is called once per frame
void Update () {
if (fadeLight.intensity == 0)
{
direction = true;
}
else if (fadeLight.intensity == 8)
{
direction = false;
}
if(direction)
{
fadeLight.intensity += 0.1f;
}
else if (!direction)
{
fadeLight.intensity -= 0.1f;
}
}
}
All it’s doing is making the light pulse using the intensity variable. This works fine when attached directly to a light.
However, if I make fadeLight public and try to attach the script to an object, say a cube, and reference this light like below:

Where “Point light” is written changes to “None” as soon as I hit play, and returns as soon as I quit playing. If I drag the light source over during play, the script works as intended.
Basically, why does it lose the reference? Every Unity video I’ve seen on scripting tells me this should work.
Thanks to anyone who can help, I’ve felt like a right tool for the last week or two.