P
P
Pavel Arutyunov2022-03-18 16:22:47
Mobile development
Pavel Arutyunov, 2022-03-18 16:22:47

How to make an object fade in Unity2D through the OnTriggerEnter2D function?

Hello!
I want to implement the following function: when a player enters an opaque texture (that is, into a Trigger), then it becomes transparent, and when it leaves the Trigger's field of action, it becomes opaque again.
Please help, thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
K0TlK, 2022-03-18
@K0TlK

Change the color property of the SpriteRenderer component. The Color type has 4 channels - red, green, blue and alpha (R,G,B,A). A is responsible for transparency. Accordingly , there will be a translucent sprite. When entering the trigger, we decrease the alpha channel, when we exit, we increase it. new Color(1f, 1f, 1f, 0.5f)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question