#transition fade screen
1 messages · Page 1 of 1 (latest)
did you get it working ?
well...
ok so you're still missing references to the Fade Images
and fadeColor is not needed anymore
you have these two
one of them is Full Alpha / Visible
and other has alpha at 0
meaning transparent
oh you're missing a parameter still.
these screenshots are blinding
lightmode 😵💫
read the errors they usually say whats wrong
the method FadeToColor has 3 parameters , you're passing 2
oh I forgot the code snippers
right, do you see the signature
why are you giving it 2 colors
its expecting Image Color float
I don't see how i'm giving 2 colors
am i supposed to jsut have fadeincolor in the first one and fadeoutcolor in the second one?
void FadeScreen()
{
StartCoroutine(FadeToColor(fadeInColor));
StartCoroutine(FadeToColor(fadeInColor));
StartCoroutine(FadeToColor(fadeInColor));
}
IEnumerator FadeToColor(Image fadeImg, Color endColor, float duration)
{
float elapsedTime = 0f;
Color startColor = fadeImg.color;
while (elapsedTime < duration)
{
elapsedTime += Time.deltaTime;
float t = Mathf.Clamp01(elapsedTime / duration);
fadeImg.color = Color.Lerp(startColor, endColor, t);
yield return null;
}
fadeImg.color = endColor;
}
what about now?
you're passing 1 thing while the method expects 3 things..
but I have 3 different cameras and 3 different ui images for transition fade in and fade out
the cameras are irrelevant at this point
forget the camera
you had 3 parameters before, you need to write how you had it expect replace camera with image reference
void FadeScreen()
{
StartCoroutine(FadeToColor(fadeInColor));
}
IEnumerator FadeToColor(Image fadeImg, Color endColor, float duration)
{
float elapsedTime = 0f;
Color startColor = fadeImg.color;
while (elapsedTime < duration)
{
elapsedTime += Time.deltaTime;
float t = Mathf.Clamp01(elapsedTime / duration);
fadeImg.color = Color.Lerp(startColor, endColor, t);
yield return null;
}
fadeImg.color = endColor;
}
again, you're missing fadeImg and duration
void FadeScreen()
{
StartCoroutine(FadeToColor(fadeInColor, fadeImg, duration));
}
IEnumerator FadeToColor(Image fadeImg, Color endColor, float duration)
{
float elapsedTime = 0f;
Color startColor = fadeImg.color;
while (elapsedTime < duration)
{
elapsedTime += Time.deltaTime;
float t = Mathf.Clamp01(elapsedTime / duration);
fadeImg.color = Color.Lerp(startColor, endColor, t);
yield return null;
}
fadeImg.color = endColor;
}
oh god, are you just guessing at this point
isn't the code editor yelling at you with errors?
then what am i supposed to write?
this is all due missing basic c# fundamentals you cannot recognize a simple issue
the order in which you pass the types the method expects matters
you cannot mix them around..
if someone asks you for your date of birth, do you give them the year first ?
year are last
alr well is fadeInColor an Image
cause the method is expecting an Image at the first
you need the instance of an image
Image is a class, just a blueprint to an object
its not an actual instance of object
what am i supposed to write instead of Image?
wdym write the things you want to animate...
fade or whatever
you need those references a while ago I said it
replace the Camera with Image that meant everywhere in the code
this one?
right
your transition
is it not have the Image component
having Camera would not make sense
as said already Camera.backgroundColor doesn't do anything in this case
the script doesn't know which Image you want, that is why we make fields
so you can assign it to them
ok
did you assign them inside the inspector?
how did you assign AudioClip
the same exact way
drag n drop
why are the cameras still there?
I removed them and replaced with iamge
I don't get ti
did you save the changes on script?
also you dont need fadeColor anymore, remove it for less confusion
yes
press backspace on those camera in the field remove see if says Image
if it doesn't your script didn't compile
the whole fadescreen or the whole startcoroutine?
what , i was talking about these.
but looks like you probably saved the script with errors..
you have to fix the errors
I meant that
no remove the Field that says fadeColor
the old one
how can i fix the errors?
write the methods properly..
not much left to do, you already made the fields for Image
now put them to use with the color..
You have all the ingredients
you just need to use them in the right order
I don't know the order of image, color and float
you just said it..
think for a moment
the method is Image, Color, Float
why are you passing, Image, Image, Image
oh wait saw the second screenshot
what does error say ?
in second image
still nothing changed
by enabled, you mean visible?
but then the white image will just cover up the screen in the start
you can
either enable / disable the image component inside the coroutine
or
keep the object as is now and just start it with the color alpha set to 0 already
ok, there, so what is your feedback?
looks good
alright, anymore feedback if there should something to be improved? I did heard you said something like curve
The animation curve can get complex
oh
yet I also don't know why player 2 won't interact with the door even though I presses ".", did I missed something?
if (other.CompareTag(playerTag))
{
isPlayerInRange = true;
}```
are you only check for `playerTag`
do both players have tag as "Player"
the second player have tag name "Player 2"
so I have to put in isPlayer2InRange?
I would use a script called Player on both players
then only check for a Player
this way it only cares that its a player
you wont need this GameObject player = GameObject.FindGameObjectWithTag(playerTag);
both players have the same PLayer script
will it only ever be 2 players or more?
only 2 players
private Player playerOne, playerTwo;
ok
they both also have tag names
Player 1's tag name is "Player" while player 2's tag name is "Player 2"
void OnTriggerEnter2D(Collider2D other)
{
if (other.TryGetComponent(out Player player))
{
if(player.CompareTag(playerTag)) playerOne = player;
else if(player.CompareTag(player2Tag)) playerTwo = player
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.TryGetComponent(out Player player))
{
if(player.CompareTag(playerTag)) playerOne = null;
else if(player.CompareTag(player2Tag)) playerTwo = null
}
}```
you need a smart way to check for key presses since they're both different
but if I change their tag names, I must restart everything
where do you see anything about changing names?
you Do not meant by tag name changing, do you?
no
i was saying just store it based on tag
but putting a keycheck inside this script doesn't make much sense since now you need two different scripts for each player
you should call the teleport method from the player itself on its interaction method
its missing extra )
but dont bother doing it this way.. its overcomplicated
just call Teleport from the player, have it pass itself
TryGetComponent still missing )
how can I call teleport from the player, while it only worked for player 1 but not player 2?
oh
its because you only checked for playerOne tag and not playerTwo, also their keys are probably different no ?
so having it inside the door trigger itself makes no sense you would need to check for both keys and both tags but thats overcomplicated
put interaction key on player then find the door DoorInteraction via trigger
same as now
yes because you sill need way to check both players / both keys
but how?
its complicated, just do it the other way around
...?
inside the player script put
OnTriggerEnter2D
then check for DoorInteraction
void OnTriggerEnter2D(Collider2D other)
{
if (other.TryGetComponent(out DoorInteraction door))
{
door.TeleportPlayer(transform)
}
}
then I don't need this?
inside DoorInteraction script
public void TeleportPlayer(Transform player)
{
FadeCameras();
{```
get rid of GameObject player = GameObject.FindGameObjectWithTag(playerTag);
You should probably make a bool like the interaction script, this will instantly teleport it when it touches
my oversight on that
make a bool in playerscript
private bool?
ye
same exact logic as the old one in InteractionDoor script
Oh and you need to store the door too now
you can use that as your bool
private bool TeleportPlayer = false;?
private DoorInteraction door;
void OnTriggerEnter2D(Collider2D other)
{
if (other.TryGetComponent(out DoorInteraction d))
{
door = d;
}
}```
still in the player script
if(Input.GetKeyDown(interactionButton))
{
if(door != null) {
door.TeleportPlayer(transform); }
}```
void OnTriggerExit2D(Collider2D other)
{
if (other.TryGetComponent(out DoorInteraction _))
{
door = null;
}
}```
this will be cleaner for now than doing it from the door script itself to know which key was pressed
the GetKeyDown part goes in Update
never check input inside the Trigger method
also you need the interactionButton on each player
so make the field for it
why is it letter d and _?
Void Update?
_ is a discard symbol , slight optimization not important
meaning you will not need to store it in a local variable, the found DoorInteraction since it will not be used in TriggerExit
d is just a variable name for the local found component of type DoorInteraction
is still red underlines
did you make the changes to TeleportPlayer of
DoorInteraction
this is on the player ?
yes
ok now go to the DoorInteraction script again
fix TeleportPlayer
to take in a Transform and make it public
the first two lines change it to this
#1217971565325713479 message
and get rid of the Tag part
what tag part?
I don't see it anywehre in door interaction script
what?
can you send the new DoorInteraction script
uh well did you create one
you should probably use Keycode instead of string
[SerializeField] private KeyCode interactionButton;
did you make the field or not...
wait I think is because you wrote the "b" small instead of big "B" on button
ok, there
try not to blindly copy , cause then my mistakes = yours
gotta sorta understand why you're making those changes and what they are for
again basic C# thing, declaring fields etc.
is that it?
should be
its not that diffcult , this would take a few minutes just have to grasp the pattern in unity
the error is telling you exactly whats wrong
"already defines a member called OnTriggerExit2D"
you have two of the same method with same exact parameters inside this script
then what should i do? I can't put in witht he others together sunce they haveprivate void OnTriggerExit2D(Collider2D collision) and void OnTriggerExit2D(Collider2D other)
have you thought that maybe you could, you know combine them lol
before you ask me the obvious, put whats Inside one method into the other
the name of the parameter is inconsequential they are exactly the same as far as computer is concerned.
they're both defined as Collider2D type parameters
therefore they do exactly the same thing
now the transition isn't like before
there's no this whole fadein and out
it's comletely gone now
is it teleporting both players?
yes
so its just the fade?
and the duration
are both the transition objects enabled?
and what is fadeDuration set to inside the inspector
look at the difference between these videos with duration and fade in and out
yes
does the sound play ?
oh?
by the time player is teleport the Fade already starts back to fadeout
make a fade out method
put those inside
and also, I can't see any invoke in doorinteraction script in the new one
yes thats why
what should I write? since I already pasted the new one that i forgot what the old one looked like
even the fade in and out works, the duration doesn't work
also sometimes when I click the button everytime, I cannot go in the door again
because I noticed that everytime I press q multiple times
maybe invoke delay has to be higher?
could be issue being spawned already inside trigger
might need to switch that part to OnTriggerStay
for door = d
fade duration is for how long the white image will fade in and fade out
I also still instant teleport
so switch it to how it was originally
see if that helps the keypress issue
You wrote it wrong its OnTriggerStay2D
also realized the old method was delaying the teleport itself thats why
easy fix
I still isntant teleport
thats for something else
oh
easy fix
uhhh.... what should I change?
public void TeleportPlayer(Transform player)
{
FadeScreen();
AudioSource.PlayClipAtPoint(doorSound, transform.position);
StartCoroutine(Teleport(player, fadeDuration)) ;
}
private IEnumerator Teleport(Transform player, float waitTime)
{
yield return new WaitForSeconds(waitTime);
player.transform.position = teleportTarget.position;
StartCoroutine(FadeToColor(transition, fadeOutColor, fadeDuration));
StartCoroutine(FadeToColor(transition2, fadeOutColor, fadeDuration));
StartCoroutine(FadeToColor(transitionPixel, fadeOutColor, fadeDuration));
}```
it is working, but the transition fade in and out..
wdym by that
is that the transition is not doing right that instead of for one of the players, all the whole screen fades to white
well yeah you're fading 3 different screens each time player goes inside
computer only does what you tell it to do
but it's supposed to be just one of the player's screen to fade to white based on which player enter the door
so tell the computer to do that instead
You have the player already
but how am i able to tell the computer that?
well you know each player has a different
tag
exactly
based on that you can figue out which player is coming in Teleport, check tag then split the StartCoroutine into sepearate ones based on If condition
also why do you have 3 Image/screens instead of 2
the third screen would be for single player
well there is another condition then
dont worry about that one yet, start with one each player
ok
hmmm.... I don't know how to do write that
sure you do, you written if statements before and checking tag correct?
you just need to split up StartCoroutine for fades into different if statements
like this?
not at all
none of those are what I mentioned
I said if statements first of all, I mentioned Checking for tag. You use if statements for that.
also those 3 will need to be moved to TeleportPlayer
alr thats half way there
you need inside there to check tag on the player
based on tag, start a certain coroutine
what?
what ur confused on 
I just don't know where in place to put the tag in
inside teleportplayer I told you this
you have to check it ,
just how you check tags every other place in your code
I meant startcourine
if(player.CompareTag(p1Tag)) StartCoroutine(p1Screen
etc..
I did thought for the same player 1 but I don't know about that will affect the the co op
it still go all transitions
well if it fills only screen of player 1 should not matter, if it fills whole screen then you should consider distingish it
debug it then because it shouldn't
well I only noticed one small difference between the two transitions in fade in and out
are they still fading together ?
cause if one starts before the other you will prob notice issue
they seem to start at the same time but at a different speed, based on which playet interact with the door
oh also you prob want to start the fade outs also depending on player
maybe related or not
for the first player if playing single player
oh wait, both of the transitions works, is just that the pixel transition is doing that
thought so 😉
btw is the other thing fixed ? mashing the interact button on door ?
let's see
so just the fade breaks?
well if I like spam clicking
man we sure have been in this for a long time now, same here
haha yup and Luckly I was only working on 3 project while at it instead of the usual 5 
XD
5 hours
as long I'll wait till you respond
I meant I improved the ui image by making it stay longer
and the part you say this whole spam clicking thing on the door like it's seen in the video can be debugged. I'll be still waiting if you have time
sure, just need an exact breakdown on when it happens exactly, to further narrow down issue
uhhh I did not get what you mean
the bug?
does it stop working completely or does it work after some time?
could be issue with the coroutines
it is working, it just that like if you keep on spamclikcing by the portal you might get teleported multiple times and bad timings
yeah because of the delay inside the method is doing one thing while another thing
doing multiple coroutines at same time it confuses it
you have to put something to tell isBusy if its busy then you dont run teleport until busy is done
ok
fixed it ?
yeah

also what do you think of the portal animation?
looks better yea, though personally I prefer black over white
black over white?
I don't know about that
should we take this whole thing here?
is it ok for you to talk about like the door unlock buttons here or not?
make a separate thread if possible describing new issue with clear info avail.
For future I'd post the question inside code channels first, I'd rather not have to personally answer each inquiry
