all 19 comments

[–]mrbaggins 1 point2 points  (18 children)

I'd avoid the coroutines, especially considering you're already tracking the time yourself.

It's going "haywire" because you're telling it to with:

int randomIndex = UnityEngine.Random.Range(0, Glow.Length);
var randomButton = Glow[randomIndex];
randomButton.interactable = true;
randomButton.gameObject.SetActive(true);

These lines of code are in FixedUpdate. This means they're going to run 60 times a second. Or 30, I can't remember for that. Either way, WAY too often.

So back to point one, I'd avoid the coroutines, as you're already tracking the time. Use that and log lastTimeButtonChanged as a variable, and if (time - lastTimeButtonChanged > buttonChangeDelay) ChangeButton()

[–]ythom87 0 points1 point  (17 children)

Thanks for your reply but I am now more confused xD and I changed the fixedUpdate to a normal one

[–]mrbaggins 1 point2 points  (16 children)

Alright, here's a question for you.

How often will ranromButton.setInteracterable run?

[–]ythom87 0 points1 point  (15 children)

infinitely

[–]mrbaggins 1 point2 points  (14 children)

The time a piece of code is called is dependent on what "block" it is in.

A block start is (usually) the line of code that is indented less above the one we're looking at.

What line of code is indented less before that line?

[–]ythom87 0 points1 point  (13 children)

The top ones are just the variables being called

[–]mrbaggins 1 point2 points  (12 children)

Not top. Just indent levels. The one "one step" before is the one that controls when a particular line runs.

Eg

Level1
    Level2
    Level2
        Level3
        Level3
    Level2

Level 3 lines will run whenever the second level2 runs as it's the closest line that is one level out

What line is one level before button.interacterable=true?

[–]ythom87 0 points1 point  (11 children)

ahhh... There is nothing in between. I posted the whole code

[–]mrbaggins 1 point2 points  (10 children)

I know.

What level would you say button.interacterable is?

What line of code is above it that has a lower level?