So I made this basic code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lumos : MonoBehaviour
{
public GameObject lumosLight;
void Update()
{
if (Input.GetButtonDown ("off"))
{
lumosLight.SetActive (false);
//bound to mouse 1
}
if (Input.GetButtonDown ("on"))
{
lumosLight.SetActive (true);
//bound to mouse 0
}
}
}
And what I basicly want to do is when I left click a light appears, and when I right click it goes away again. The disappearing (false) is working fine, if I load it as active and then right click the light goes away. Somehow the problem is that the appearing (true) will not work, no matter what I do, the light won’t get on again. How could this be?
I would like to hear what you pro’s have to say 
I’d troubleshoot this by first replacing line 19 with:
if (Input.GetMouseButtonDown(0))
If that doesn’t change anything I’d try swapping line 15 and line 21 to reverse the logic, and see if the problem appears to be tied to the mouse button or to setting the gameobject to active.
That should narrow down the issue at least.
Your code looks fine, and I tested it… it definitely works.
I think the problem is in your input manager. It’s case sensitive, for one… verify you have it lowercase there too. And verify your on is set up just like your off, but with just the button different.
I already tried to make it output a simple console string like Hello and Goodbye and that worked, I tried swaping and that worked, it really is the game object.
May it be because I am spawning a point light? Like, it is not rendering or so, I dunno
No it’s not, I’ve changed it to a box and once again it disapairs, but won’t apear again after that.
I’m just guessing, but does this script component happen to be attached to the same GameObject you set to inactive? In that case, Update on your script would also stop being called every frame.
2 Likes
You may actually be onto something!
What I did find with adding the light and a console string at the same time, as long as the light is on (from the start) left clicking would call the message, but once I right click the message from the right button gets called, and left clicking will not call the other message again, like it somehow blocks left click once right click is triggered.
The blocking may be because the object goes inactive so the script goes too, brb!
YES! thanks so much for the help Thomas, it was fixed xD.
I guess I learned something today