#https://gdl.space/isupovotim.cs like
1 messages · Page 1 of 1 (latest)
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);
}```
...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
I forgot to reset the timer = 0f; for the second fade, I've edited the above
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
Where's the gameobject that has this script?
Oh right. It’s on multiple objects.. the new scene loads and destroys it.. that’s why no fade off
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
Yeah. Like I said, pseudo code.. it’s not in a copy paste format
oh
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
but what happened with the P2 thing? which would allow you to choose 1 player or 2 players?
imma try something
I didn't know what that was or what it was for
hang on, lemme try what you did first
am i supposed to put it there?
because i can't put the canvas in loader canvas group
because the canvastransition is the parent to the image fade
put it on the canvas, a DDOL object needs to be on the parent
oh, but what about this whole canvas group thing? i can't put anything in there
it's a component, add it to the canvas
the level loader is on the "canvas" but I can't put in anything there (canvas group)
yes you can
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
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
like this?
erm....
something doesn't seem right
click on that and show me what it says, some extra info should come up below
but hwne i click on it, nothing can be found
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
Find loaderCanvasGroup.alpha = alpha; and copy the below
Debug.Log($"alpha is: {alpha} - load scene {loadScene}");
loaderCanvasGroup.alpha = alpha;
yield return new WaitForSeconds(1f);
I can't find it
line 59 in LevelLoader.cs
but it says loaderCanvasGroup.alpha = Math.Lerp (0f, aplha, t). not loaderCanvasGroup.alpha = alpha;
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
Show me the inspector for UIContainer, and the child image
set the alpha on the colour to full
this whole not fading away thing is literally the same like before
it's different
I see no difference with the white image, it didn't fade away when going on the next scene
I know the mistake
This can just replace the entire LevelLoad.cs https://gdl.space/kuduqodapo.cs
uhm, there is a red underline
sorry, that doesn't show in VSC for me.. was just a quick edit
change to loaderCanvasGroup.alpha = toAlpha;
it's working now, but I still don't get what is with the error that is popping up
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;
}
it's still popping up
lemme see what you've done to the code
oh, ait, i jusr realised
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
🥳
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
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
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
you can show me, but depending how much needs changing..
ok, I know how levelbutton script looks like
https://gdl.space/inegugafub.cs this is the script for choosing amount of players
https://gdl.space/verajevaqe.cs and here's that I'm trying to put that coding in the levelbutton script
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;
}```
but i will get error if i do that
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
ok
no there's no longer errors (because i removed some that is finding playermanager
now that i have removed the errors
Is this correct?
yeah, well all that is needed is this whole amount of players select thing
what happens when you click player 2 ?
2 players still appears
when you press on player 1 button, only 1 player supposed to appear
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;
}
}
did you make changes to the LevelButton.cs I gave you ?
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
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 .
Actually, use this instead https://gdl.space/vexixuqefi.cs
I just noticed your PlayerManager is a Singleton
There's stuff going on for selecting how many players that I don't have visibility of
https://gdl.space/koqeqeyahi.cpp I also have this one that is with choosing players
I did also had tag in PlayerManager in the script for players to appear before
those should be change to private as they are set via code
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
yes, dont worry about it
I just don't get what to change to private
nothing, doesn't matter
did you have a good sleep? (I just woke up)
I don't get why
it is fixed now
Congrats, well done