Weird Variable Scrope Problem

So basically in start, I am assigning DayNightController

    void Start()
    {
        DayNightController dayNightScript = DayNightCycle.GetComponent<DayNightController>();
    }

Then, when i try to access it anywhere else.

dayNightScript.daySpeedMultiplier = 0.05f;

It doesn’t recognize dayNightScript, doesnt matter where i put it, not sure why it does this…
(Its probably something simple, just cant come up with it XD)

@MatrixTai Hi. Apologies for the late reply. I set the emission strength all the way up to 99. The wall color was entirely black. It still didn't work. It only seems to be working if the wall color is lighter. I also noticed that the emission doesn't bounce of the walls if the metallic-ness of the walls' material is set high. This is not a good thing because I'm currently working on a game where an object should be emitting light over a fully metallic surface.

1 Answer

1

“Then, when i try to access it anywhere else.” Do you mean trying to access it outside Start()? That’s not possible, it’s only known in that method. You have to declare it outside:

public class YourClass : MonoBehaviour
{
    DayNightController dayNightScript;
   void Start()
    {
        dayNightScript = DayNightCycle.GetComponent<DayNightController>();
    }
}

Nop, as in i am trying to acces it a if statement in the start.

@a7BiT-psycho Well, the first part i am not 100% sure, it's a script from steamVR and it seems to be working so yeah. Anyways, just to be sure i tested it on another script, and it seems to work there, so yeah i have to figure out how to do it then, considering its a API. Anyways, thanks for the help!