#Freddy thread

1 messages · Page 1 of 1 (latest)

limpid oxide
#

Hello

#

@deft lark this works?

deft lark
#

alr

limpid oxide
#

perfect

deft lark
#

do you know which event im talking about?

#

the scene changing one

limpid oxide
#

EventSystem

#

right?

deft lark
#

you have it in your code somewhere

#

SceneManager one

limpid oxide
#

no

deft lark
#

yes

#

its in ur code u showed me

limpid oxide
#

!code

lean portalBOT
limpid oxide
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class ChangeScenes : MonoBehaviour
{
    public void Play()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 2);
    }
    public void Options()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }
    public void Quit()
    {
        Application.Quit();
        Debug.Log("Player has quit the game");
    }
    public void BackToMainMenu()
    {
        SceneManager.LoadScene(0);
    }
    
}
#

this is my code for changing scenes

deft lark
#

there is another one you had

limpid oxide
#

the dontdestroyonload one?

#

that one is in the trash

#

it was the brightness panel

deft lark
#

doesnt matter

#

read what i wrote

limpid oxide
#

I dont really understand what are you trying to explain

#

also srry for my dumbness I have wasted 2 hours of your life

deft lark
#

ok stay focused

#

you're trying to load

#

and when do you need to load

#

when scene changes

#

did you read what the link I've sent does

deft lark
#

its in plain english

limpid oxide
#

k srry

deft lark
#

subscribing is done with +=

#

unsubscribe is done with -=

#

based on that , look in the script where thats happening

limpid oxide
#

when It enables something, it subscribes to Change scene

#

when disabling, unsubscribing

#

so when it enables the method, the scene changes

deft lark
#

what

#

when you run LoadScene this is method is run

#

nothing more, nothing less

#

Loading anything should go there since you want to load the same stats in the separate scene

#

unless the script that has that stat is dontdestroyonload

#

in that cause it never gets destroyed on scene changes

#

but this can break references if you have any references to other scene objects

limpid oxide
#

using the playerprefs thing is preferrable

limpid oxide
#

when I run LoadScene is to get to the other scene, I cant put the brightness thing there

deft lark
#

all your doing is loading the values from playerpefs

#

on scene changes

#

so the post processing has the same value each scene

limpid oxide
#

how do I put that into code?

deft lark
#

this isn't the script that controls the brightness value

#

this isnt the script you save value

limpid oxide
#

so in the brightness script I load the save at the start?

#

Ok

#

I managed to get something

#

!code

lean portalBOT
limpid oxide
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Rendering.PostProcessing;

public class Brightness : MonoBehaviour
{
    public Slider BrightnessSlider;
    public PostProcessProfile brightness;
    public PostProcessLayer layer;
    AutoExposure exposure;

    void Start()
    {
        brightness.TryGetSettings(out exposure);

        float savedBrightness = PlayerPrefs.GetFloat("BrightnessSliderValue", 0.5f);
        BrightnessSlider.value = savedBrightness;
        AdjustBrightness(savedBrightness);
    }

    public void AdjustBrightness(float value)
    {
        if (value != 0)
        {
            exposure.keyValue.value = value;
        }
        else
        {
            exposure.keyValue.value = 0.05f;
        }

        PlayerPrefs.SetFloat("BrightnessSliderValue", value);
        PlayerPrefs.Save();
    }
}
#

now I need to keep the brightness when changing scenes

#

that's the thing

deft lark
#

then what that hell we've been talking about this whole time..

#

literally

#

make a Load method

#

and call it

#

when scene is changed

#

this goes inside a method

#

float savedBrightness = PlayerPrefs.GetFloat("BrightnessSliderValue", 0.5f);
BrightnessSlider.value = savedBrightness;
AdjustBrightness(savedBrightness);