Hi, I’m Luke, and I’m working on a script for Car lights for my new driving game I’m making, but When I press the play button, I keep getting the same error saying Missing component exception on The headlights, brake lights, even the reverse lights, I tried using Null method but that didn’t work.
I even tried using the GetComponent Method and that still gave me errors, what Do I do?
here’s my code.
void Start () {
light = base.gameObject.GetComponent<Light>();
animation = base.gameObject.GetComponent<Animation>();
if (animation.gameObject.GetComponent<Animation>() != null){
Debug.Log("Can't find animation");
}
}
// Update is called once per frame
void Update () {
if (isOn)
{
light.enabled = true;
}
else
{
light.enabled = false;
}
if (isOn == true && lightType == LightTypes.Indicator)
{
animation.gameObject.GetComponent<Animation>().Play();
}
else
{
animation.gameObject.GetComponent<Animation>().Stop();
}
}
}