![112244-lidopen.png](https://europe1.discourse-cdn.com/unity/original/3X/f/0/f00ef3aa4b811ce9673487f133b544fd851813e9.png)
So, my Light component keeps disappearing right after I play the scene. Does anyone know what seems to be the problem?
My console is also giving me this message:
“MissingComponentException: There is no ‘Light’ attached to the “Kansi” game object, but a script is trying to access it.
You probably need to add a Light to the game object “Kansi”. Or your script needs to check if the component is attached before using it.
LidOpen.Update () (at Assets/Scripts/LidOpen.cs:22)”
hi, what happened was, @tuomvii was getting light component which was not attached to the same gameobject that of script. so he has to remove the line :
Light = GetComponent();
and he was to give the reference from outside, or use gameObject.find() function.
is the light component attached to the same gameObject to which script is attached??
Could you show the script it is referring too? You probably destroy the object by accident
Sure,
public Animator anim;
public bool lidCheck;
public Light Light;
void Start()
{
anim = GetComponent<Animator>();
lidCheck = false;
Light = GetComponent<Light>();
}
void Update()
{
if (lidCheck == false)
{
Light.range = 2.0f;
}
}
void OnTriggerStay (Collider other)
{
if (other.gameObject.tag == "Player")
{
if (Input.GetKey(KeyCode.E))
{
anim.Play("openlid");
lidCheck = true;
}
if (Input.GetKey(KeyCode.R))
{
anim.Play("closelid");
lidCheck = false;
}
}
}
}