#transition fade screen

1 messages · Page 1 of 1 (latest)

balmy wraith
#

what

worthy kestrel
#

did you get it working ?

balmy wraith
#

well...

worthy kestrel
#

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

balmy wraith
#

should I also change tje name od "FadeToColor"?

#

since it have red underlines

worthy kestrel
#

no

#

red underlines where?

balmy wraith
#

FadeToColor have red underlines

worthy kestrel
#

well did you remove the FadeToColor coroutine ?

balmy wraith
#

no

#

I didn't

worthy kestrel
#

these screenshots are blinding

#

lightmode 😵‍💫

#

read the errors they usually say whats wrong

#

the method FadeToColor has 3 parameters , you're passing 2

balmy wraith
balmy wraith
worthy kestrel
#

why are you giving it 2 colors

#

its expecting Image Color float

balmy wraith
worthy kestrel
balmy wraith
#

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?

worthy kestrel
#

you're passing 1 thing while the method expects 3 things..

balmy wraith
#

but I have 3 different cameras and 3 different ui images for transition fade in and fade out

worthy kestrel
#

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

balmy wraith
#
 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;
    }
worthy kestrel
balmy wraith
#
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;
    }
worthy kestrel
#

isn't the code editor yelling at you with errors?

balmy wraith
#

then what am i supposed to write?

worthy kestrel
#

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 ?

balmy wraith
#

year are last

worthy kestrel
#

alr well is fadeInColor an Image

#

cause the method is expecting an Image at the first

balmy wraith
#

but Image gets red underline

worthy kestrel
#

Image is a class, just a blueprint to an object

#

its not an actual instance of object

balmy wraith
#

what am i supposed to write instead of Image?

worthy kestrel
#

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

balmy wraith
#

this one?

worthy kestrel
#

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

balmy wraith
worthy kestrel
#

ok

#

did you assign them inside the inspector?

#

how did you assign AudioClip

#

the same exact way

#

drag n drop

balmy wraith
#

why are the cameras still there?

#

I removed them and replaced with iamge

#

I don't get ti

worthy kestrel
#

also you dont need fadeColor anymore, remove it for less confusion

balmy wraith
worthy kestrel
#

if it doesn't your script didn't compile

balmy wraith
#

the whole fadescreen or the whole startcoroutine?

worthy kestrel
#

but looks like you probably saved the script with errors..

#

you have to fix the errors

worthy kestrel
#

the old one

balmy wraith
worthy kestrel
#

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

balmy wraith
#

I don't know the order of image, color and float

worthy kestrel
#

you just said it..

balmy wraith
#

ok, I don't know what I'm supposed to write

#

I'm so lost right now

worthy kestrel
#

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

balmy wraith
worthy kestrel
#

uh yeah make sure you did assign those in the inspector btw

balmy wraith
worthy kestrel
#

transition

#

gameobject

balmy wraith
worthy kestrel
#

guess thats a clear No

#

that explains why its doing nothing

balmy wraith
#

by enabled, you mean visible?

worthy kestrel
#

its literally Disabled

#

It will never be visible

balmy wraith
worthy kestrel
balmy wraith
worthy kestrel
balmy wraith
#

alright, anymore feedback if there should something to be improved? I did heard you said something like curve

worthy kestrel
balmy wraith
#

oh

#

yet I also don't know why player 2 won't interact with the door even though I presses ".", did I missed something?

worthy kestrel
# balmy wraith oh
 if (other.CompareTag(playerTag))
        {
            isPlayerInRange = true;
        }```
are you only check for `playerTag`
#

do both players have tag as "Player"

balmy wraith
#

the second player have tag name "Player 2"

worthy kestrel
#

guess that answers that

#

you're only checking for "Player"

balmy wraith
#

so I have to put in isPlayer2InRange?

worthy kestrel
#

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);

balmy wraith
#

both players have the same PLayer script

worthy kestrel
balmy wraith
#

only 2 players

worthy kestrel
#

private Player playerOne, playerTwo;

balmy wraith
#

ok

worthy kestrel
#

ideally you'd make an ID or enum for Player1, Player2

#

you could use a tag too ig

balmy wraith
#

they both also have tag names

#

Player 1's tag name is "Player" while player 2's tag name is "Player 2"

worthy kestrel
#
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

balmy wraith
#

but if I change their tag names, I must restart everything

worthy kestrel
#

wdym change their names?

#

where do you see changing tags

balmy wraith
worthy kestrel
#

where do you see anything about changing names?

balmy wraith
worthy kestrel
#

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

balmy wraith
worthy kestrel
#

but dont bother doing it this way.. its overcomplicated

#

just call Teleport from the player, have it pass itself

balmy wraith
worthy kestrel
#

TryGetComponent still missing )

balmy wraith
balmy wraith
worthy kestrel
#

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

balmy wraith
#

now I*m unable to go in the doors

worthy kestrel
#

yes because you sill need way to check both players / both keys

balmy wraith
#

but how?

worthy kestrel
balmy wraith
#

...?

worthy kestrel
#

then check for DoorInteraction

#

void OnTriggerEnter2D(Collider2D other)
{
if (other.TryGetComponent(out DoorInteraction door))
{
door.TeleportPlayer(transform)
}
}

balmy wraith
balmy wraith
worthy kestrel
#

nah

#

u dont need any of that

#

just FadeToColor, TeleportPlayer and FadeCameras

balmy wraith
worthy kestrel
#

inside DoorInteraction script

#
  public void TeleportPlayer(Transform player)
    {
       FadeCameras();
        {```
#

get rid of GameObject player = GameObject.FindGameObjectWithTag(playerTag);

worthy kestrel
# balmy wraith

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

balmy wraith
#

private bool?

worthy kestrel
#

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

balmy wraith
#

private bool TeleportPlayer = false;?

worthy kestrel
#
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

balmy wraith
worthy kestrel
#

never check input inside the Trigger method

#

also you need the interactionButton on each player

#

so make the field for it

balmy wraith
#

why is it letter d and _?

balmy wraith
worthy kestrel
# balmy wraith why is it letter d and _?

_ 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

balmy wraith
#

is still red underlines

worthy kestrel
#

DoorInteraction

balmy wraith
worthy kestrel
balmy wraith
#

yes

worthy kestrel
#

ok now go to the DoorInteraction script again

#

fix TeleportPlayer

#

to take in a Transform and make it public

worthy kestrel
#

and get rid of the Tag part

balmy wraith
#

what tag part?

worthy kestrel
#

inside TeleportPlayer

balmy wraith
worthy kestrel
#

did you remove FadeCameras too ?

#

why is the rest of Teleport player Gone

balmy wraith
balmy wraith
worthy kestrel
#

can you send the new DoorInteraction script

balmy wraith
worthy kestrel
#

does it make more sense now ?

balmy wraith
#

ok

#

but the interactionbutton is still red underline in player script

worthy kestrel
#

you should probably use Keycode instead of string

#

[SerializeField] private KeyCode interactionButton;

#

did you make the field or not...

balmy wraith
#

wait I think is because you wrote the "b" small instead of big "B" on button

#

ok, there

worthy kestrel
#

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.

balmy wraith
#

is that it?

worthy kestrel
#

should be

#

its not that diffcult , this would take a few minutes just have to grasp the pattern in unity

balmy wraith
worthy kestrel
#

"already defines a member called OnTriggerExit2D"

#

you have two of the same method with same exact parameters inside this script

balmy wraith
#

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)

worthy kestrel
#

before you ask me the obvious, put whats Inside one method into the other

balmy wraith
#

what i meant is the first one have collision and the sceond one have other

worthy kestrel
# balmy wraith

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

balmy wraith
#

there's no this whole fadein and out

#

it's comletely gone now

worthy kestrel
#

both

worthy kestrel
balmy wraith
#

yes

worthy kestrel
#

so its just the fade?

balmy wraith
#

and the duration

worthy kestrel
#

are both the transition objects enabled?

#

and what is fadeDuration set to inside the inspector

balmy wraith
balmy wraith
# balmy wraith

look at the difference between these videos with duration and fade in and out

worthy kestrel
#

does the sound play ?

balmy wraith
#

yeah

#

I'm so confused, why did it changed so drastically?

worthy kestrel
#

ohh right iknow whats wrong

#

its happening instantly

#

before you had Invoke.

balmy wraith
#

oh?

worthy kestrel
#

by the time player is teleport the Fade already starts back to fadeout

#

make a fade out method

#

put those inside

balmy wraith
#

and also, I can't see any invoke in doorinteraction script in the new one

worthy kestrel
#

yes thats why

balmy wraith
#

what should I write? since I already pasted the new one that i forgot what the old one looked like

balmy wraith
#

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

worthy kestrel
worthy kestrel
#

might need to switch that part to OnTriggerStay

#

for door = d

balmy wraith
#

I also still instant teleport

worthy kestrel
balmy wraith
worthy kestrel
balmy wraith
#

it doesn't help and I got an error

worthy kestrel
#

also realized the old method was delaying the teleport itself thats why

#

easy fix

balmy wraith
#

I still isntant teleport

worthy kestrel
#

thats for something else

worthy kestrel
#

easy fix

balmy wraith
#

uhhh.... what should I change?

worthy kestrel
#
 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));
 }```
balmy wraith
worthy kestrel
balmy wraith
# balmy wraith

is that the transition is not doing right that instead of for one of the players, all the whole screen fades to white

worthy kestrel
#

well yeah you're fading 3 different screens each time player goes inside

#

computer only does what you tell it to do

balmy wraith
#

but it's supposed to be just one of the player's screen to fade to white based on which player enter the door

worthy kestrel
#

You have the player already

balmy wraith
#

but how am i able to tell the computer that?

worthy kestrel
#

well you know each player has a different

balmy wraith
#

tag

worthy kestrel
#

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

balmy wraith
#

the third screen would be for single player

worthy kestrel
#

well there is another condition then

#

dont worry about that one yet, start with one each player

balmy wraith
#

ok

balmy wraith
worthy kestrel
#

you just need to split up StartCoroutine for fades into different if statements

balmy wraith
#

like this?

worthy kestrel
#

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

balmy wraith
worthy kestrel
#

alr thats half way there

#

you need inside there to check tag on the player

#

based on tag, start a certain coroutine

balmy wraith
#

what?

worthy kestrel
#

what ur confused on UnityChanThink

balmy wraith
#

I just don't know where in place to put the tag in

worthy kestrel
#

you have to check it ,

#

just how you check tags every other place in your code

balmy wraith
#

I meant startcourine

worthy kestrel
#

if(player.CompareTag(p1Tag)) StartCoroutine(p1Screen
etc..

balmy wraith
worthy kestrel
#

also what about the third one

balmy wraith
#

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

worthy kestrel
worthy kestrel
balmy wraith
#

well I only noticed one small difference between the two transitions in fade in and out

worthy kestrel
#

are they still fading together ?

#

cause if one starts before the other you will prob notice issue

balmy wraith
#

they seem to start at the same time but at a different speed, based on which playet interact with the door

worthy kestrel
#

oh also you prob want to start the fade outs also depending on player

#

maybe related or not

balmy wraith
#

huh?

#

I did not get what you mean, that with related

worthy kestrel
#

the fade out i was talking about but nvm

#

what is transitionPixel tied to ?

balmy wraith
#

for the first player if playing single player

#

oh wait, both of the transitions works, is just that the pixel transition is doing that

worthy kestrel
#

thought so 😉

#

btw is the other thing fixed ? mashing the interact button on door ?

balmy wraith
worthy kestrel
#

so just the fade breaks?

balmy wraith
#

well if I like spam clicking

worthy kestrel
#

im sure it can be debugged

#

I'm pooped for the night tho

balmy wraith
#

man we sure have been in this for a long time now, same here

worthy kestrel
#

haha yup and Luckly I was only working on 3 project while at it instead of the usual 5 UnityChanLOL

balmy wraith
#

XD

balmy wraith
#

5 hours

balmy wraith
#

that the ui image stays a bit longer

balmy wraith
worthy kestrel
#

huuh ?

#

also I don't get notified without @

#

or reply

balmy wraith
balmy wraith
worthy kestrel
balmy wraith
#

ok

#

exact breakdown?

worthy kestrel
#

how are you able to break it

#

what steps you took to break it

balmy wraith
#

uhhh I did not get what you mean

worthy kestrel
#

the bug?

balmy wraith
#

uhh... that is when I keep on spam-clicking on the button

worthy kestrel
# balmy wraith

does it stop working completely or does it work after some time?

#

could be issue with the coroutines

balmy wraith
worthy kestrel
#

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

balmy wraith
#

ok

balmy wraith
worthy kestrel
balmy wraith
#

yeah

worthy kestrel
balmy wraith
#

also what do you think of the portal animation?

worthy kestrel
#

looks better yea, though personally I prefer black over white

balmy wraith
balmy wraith
balmy wraith
#

should we take this whole thing here?

balmy wraith
worthy kestrel