#https://gdl.space/isupovotim.cs like

1 messages · Page 1 of 1 (latest)

fair bolt
#
private IEnumerator LoadAndFade()
{
    float timer = 0f;
    Color startColor = uiImage.color;
    Color endColor = Color.white;

    while (timer < fadeDuration)
    {
        timer += Time.deltaTime;
        float t = timer / fadeDuration;
        uiImage.color = Color.Lerp(startColor, endColor, t);
        yield return null;
    }

    uiImage.color = endColor;

    yield return new WaitForSeconds(displayDuration);

    // Transition to the next scene
    SceneManager.LoadScene(sceneToLoad);

    // Start the fade-out animation in the new scene after a brief delay
    yield return new WaitForSeconds(0.5f);

    timer = 0f;
    startColor = uiImage.color;
    endColor = Color.clear;

    while (timer < fadeDuration)
    {
        timer += Time.deltaTime;
        float t = timer / fadeDuration;
        uiImage.color = Color.Lerp(startColor, endColor, t);
        yield return null;
    }

    uiImage.color = endColor;
    uiImage.gameObject.SetActive(false);
}```
oblique sundial
#

oh

#

I'm sorry for making you fustrated, I am not one of the most smartest ones

fair bolt
#

dont put yourself down like that

#

you're not a coder

oblique sundial
#

...yeah, I am mostly used to be a designer than a coder (because art and drawings is what I always do) (and knowing how complex coding language is and the way i tend to forget thing seasily), I just only wanted to move the project forward

fair bolt
#

I forgot to reset the timer = 0f; for the second fade, I've edited the above

oblique sundial
#

it still the same

fair bolt
#
private IEnumerator LoadAndFade()
{
    float timer = 0f;
    Color startColor = uiImage.color;
    Color endColor = Color.white;
Debug.Log($"Fading to white");
    while (timer < fadeDuration)
    {
        timer += Time.deltaTime;
        float t = timer / fadeDuration;
        uiImage.color = Color.Lerp(startColor, endColor, t);
        yield return null;
    }

    uiImage.color = endColor;

    yield return new WaitForSeconds(displayDuration);
Debug.Log($"Loading Scene");
    // Transition to the next scene
    SceneManager.LoadScene(sceneToLoad);

    // Start the fade-out animation in the new scene after a brief delay
    yield return new WaitForSeconds(0.5f);

    timer = 0f;
    startColor = uiImage.color;
    endColor = Color.clear;
Debug.Log($"Fading to clear");
    while (timer < fadeDuration)
    {
        timer += Time.deltaTime;
        float t = timer / fadeDuration;
        uiImage.color = Color.Lerp(startColor, endColor, t);
        yield return null;
    }

Debug.Log($"end colour and deactivate");
    uiImage.color = endColor;
    uiImage.gameObject.SetActive(false);
}
#

added debug logs, these will log to the console so we can see if it's doing everything

oblique sundial
#

looks like fading to clear is not being called

fair bolt
#

stop pausing it

#

and turn off maximise on play

oblique sundial
fair bolt
#

Where's the gameobject that has this script?

oblique sundial
fair bolt
#

Oh right. It’s on multiple objects.. the new scene loads and destroys it.. that’s why no fade off

oblique sundial
#

oh...

#

so how do i fix that?

fair bolt
#

What you need to do is...
The fade and level load needs to be a singleton, which puts it in DDOL.
Each level button should have a new class on, which calls the singleton.

psuedo code

public class LevelLoader : MonoBehaviour
{
  private void Awake() { // singleton stuff }
  
  public void LoadLevel(string sceneName) => StartCoroutine(sceneName);

  private IEnumerator LoadAndFade(string sceneName)
{
    float timer = 0f;
    Color startColor = uiImage.color;
    Color endColor = Color.white;
Debug.Log($"Fading to white");
    while (timer < fadeDuration)
    {
        timer += Time.deltaTime;
        float t = timer / fadeDuration;
        uiImage.color = Color.Lerp(startColor, endColor, t);
        yield return null;
    }

    uiImage.color = endColor;

    yield return new WaitForSeconds(displayDuration);
Debug.Log($"Loading Scene");
    // Transition to the next scene
    SceneManager.LoadScene(sceneToLoad);

    // Start the fade-out animation in the new scene after a brief delay
    yield return new WaitForSeconds(0.5f);

    timer = 0f;
    startColor = uiImage.color;
    endColor = Color.clear;
Debug.Log($"Fading to clear");
    while (timer < fadeDuration)
    {
        timer += Time.deltaTime;
        float t = timer / fadeDuration;
        uiImage.color = Color.Lerp(startColor, endColor, t);
        yield return null;
    }

Debug.Log($"end colour and deactivate");
    uiImage.color = endColor;
    uiImage.gameObject.SetActive(false);
}

New button class

public string sceneToLoad = "";

public void LoadScene() => LevelLoader.Instance.LoadLevel(sceneToLoad);
#

It'll take a little bit of work to swap

#

I'm off to bed now though.. cya tomorrow

oblique sundial
#

ok, cya

#

it do have many red lines though, and even hreen lines

fair bolt
#

Yeah. Like I said, pseudo code.. it’s not in a copy paste format

oblique sundial
#

oh

fair bolt
#

LevelLoader singleton - https://gdl.space/iqalirahal.cs
Put this on the parent for the white fade. Assign the UI container, add a canvas group to the UI container and assign it to the singleton

LevelButton - https://gdl.space/econohelic.cs
This goes on each of your buttons, and you need to enter the name of the scene to load. I've assumed you're using the unity event on buttons to assign the method call

oblique sundial
#

but what happened with the P2 thing? which would allow you to choose 1 player or 2 players?

#

imma try something

fair bolt
#

I didn't know what that was or what it was for

oblique sundial
#

hang on, lemme try what you did first

oblique sundial
#

because i can't put the canvas in loader canvas group

#

because the canvastransition is the parent to the image fade

fair bolt
#

put it on the canvas, a DDOL object needs to be on the parent

oblique sundial
#

oh, but what about this whole canvas group thing? i can't put anything in there

fair bolt
#

it's a component, add it to the canvas

oblique sundial
#

the level loader is on the "canvas" but I can't put in anything there (canvas group)

fair bolt
#

yes you can

oblique sundial
#

no I can't, I tried and it's not working. and when i click on the circle thing, there's nothign i can put in there

fair bolt
#

click it -> type canvas group -> enter -> drag into the field

#

you haven't added a canvas group, so you can't drag the gameobject into the field

oblique sundial
#

like this?

fair bolt
#

exactly

#

when you press play now, your 'Loader Canvas' game object should move to DDOL

oblique sundial
oblique sundial
#

something doesn't seem right

fair bolt
#

click on that and show me what it says, some extra info should come up below

oblique sundial
#

but hwne i click on it, nothing can be found

fair bolt
#

don't double click, single

#

I don't think that error matters atm.. it appears when the container gets disabled

#

can you record a vid with the 'Loader Canvas' selected, i want to watch the canvas group as you load a level

fair bolt
#

Find loaderCanvasGroup.alpha = alpha; and copy the below

Debug.Log($"alpha is: {alpha} - load scene {loadScene}");
loaderCanvasGroup.alpha = alpha;
yield return new WaitForSeconds(1f);
oblique sundial
#

I can't find it

fair bolt
#

line 59 in LevelLoader.cs

oblique sundial
#

but it says loaderCanvasGroup.alpha = Math.Lerp (0f, aplha, t). not loaderCanvasGroup.alpha = alpha;

fair bolt
#

ok, well go lower

#

it's 59 on the GDL paste, if you've changed it/ added any blank lines then I can't see that :p

oblique sundial
fair bolt
#

Show me the inspector for UIContainer, and the child image

oblique sundial
fair bolt
#

set the alpha on the colour to full

oblique sundial
fair bolt
#

it's different

oblique sundial
#

I see no difference with the white image, it didn't fade away when going on the next scene

fair bolt
#

I know the mistake

oblique sundial
#

uhm, there is a red underline

fair bolt
#

sorry, that doesn't show in VSC for me.. was just a quick edit

#

change to loaderCanvasGroup.alpha = toAlpha;

oblique sundial
fair bolt
#

Change this (image) to this:

if (loadScene == false) 
        {
            uiContainer.SetActive(false);

            loaderCanvasGroup.blocksRaycasts = false;
            loaderCanvasGroup.interactable = false;
            yield return null; 
        }
        else
        {
            SceneManager.LoadScene(sceneName);
            SceneManager.sceneLoaded += SceneLoaded;
            yield return null; 
        }
oblique sundial
#

it's still popping up

fair bolt
#

lemme see what you've done to the code

oblique sundial
#

oh, ait, i jusr realised

fair bolt
#

you didn't do what I said

#

See how you have the same thing twice, you left in the old code... those last two lines need removing

oblique sundial
#

ok

fair bolt
#

🥳

oblique sundial
#

yeah, well i did also said literally, or almost, if you look at 0:05

#

well, I guess I will keep the other button script in which you can choose 1 player or 2 players til we can figure something out later

fair bolt
#

You've got something going on with PlayerManager for loading scenes, it looks like ... which isn't good, you shouldn't do the same thing in multiple places

oblique sundial
#

oh... should i show you the PlayerManager Code?

#

and what type of button i am currently using for the player select thing?

#

I was also trying to put the script thing from the choosing player script in the LevelButton

fair bolt
#

you can show me, but depending how much needs changing..

oblique sundial
#

ok, I know how levelbutton script looks like

fair bolt
#

that's just the same code

#

and the code that matters is in PlayerManager

oblique sundial
#

down in the line 69 - 117

fair bolt
#

This shouldn't be loading the scene

public void LoadScene(bool P2, string sceneToLoad)
    {
        _nextScene = true;
        Time.timeScale = 1;
        p2 = P2;
        sceneIndex = sceneIndexFromName(sceneToLoad);
        SceneManager.LoadScene(sceneToLoad);
    }```
#

I'd change it to

public void SetPlayerCount(bool P2)
{
  _nextScene = true;
  Time.timeScale = 1;
  p2 = P2;
}```
oblique sundial
#

but i will get error if i do that

fair bolt
#

yes, because changes have consequences that also need fixing

#

I hope you can look at the information available and work out why that happens and what to do.. I really don't want to hold your hand for every single little change here

oblique sundial
#

ok

#

no there's no longer errors (because i removed some that is finding playermanager

fair bolt
oblique sundial
#

yeah, well all that is needed is this whole amount of players select thing

fair bolt
#

what happens when you click player 2 ?

oblique sundial
#

when you press on player 1 button, only 1 player supposed to appear

fair bolt
#

In PlayerManager.cs, change this:

private void LateUpdate()
    {
        if (_nextScene && SceneManager.GetActiveScene().buildIndex == sceneIndex)
        {
            SceneIsLoaded();
            _nextScene = false;
        }
    }```

to this
```cs
private void LateUpdate()
    {
        if (_nextScene)
        {
            SceneIsLoaded();
            _nextScene = false;
        }
    }
oblique sundial
#

just that?

#

hmmmm... it still ends up the same

fair bolt
#

did you make changes to the LevelButton.cs I gave you ?

oblique sundial
#

well not yet
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LevelButton : MonoBehaviour
{
[SerializeField] private string sceneToLoad;

public void OnButtonClick() => LevelLoader.Instance.LoadScene(sceneToLoad);

}

https://gdl.space/fabinalire.cs but I am trying figure out and hte red underline on SetPlayerCount

fair bolt
#

Update the LevelButton.cs I gave you to this -

#

And only have this on your buttons

#

You need to tick the bool in the inspector, on the 2 player buttons .

#

I just noticed your PlayerManager is a Singleton

oblique sundial
#

ok

fair bolt
#

There's stuff going on for selecting how many players that I don't have visibility of

oblique sundial
#

I did also had tag in PlayerManager in the script for players to appear before

fair bolt
oblique sundial
#

I don't know what to change to private

#

because i can't find anything in publics to change to private, even if i did, nothing happens in the script

fair bolt
#

yes, dont worry about it

oblique sundial
#

I just don't get what to change to private

fair bolt
#

nothing, doesn't matter

oblique sundial
#

oh ok

#

I am so stuck......

oblique sundial
oblique sundial
#

it is fixed now

fair bolt
#

Congrats, well done