Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question How to play or trigger transition in one direction

Discussion in 'UI Toolkit' started by Qriva, Sep 19, 2022.

  1. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    I want to create transition that triggers only when value is going towards one direction.
    To be more precise I want to create fade out effect - animate opacity from 1 to 0, but later when value is going from 0 to 1 I want to it to jump instantly. For example imagine simple visual element with image background, when I click it I want to fade it with uss transition, but when I click again in the middle of transition or after it finished I want opacity to jump to 1 and play fade out again.

    I tried to do some stuff with scheduler, but I am not sure this is the way. Any tips?
     
  2. pierre_10

    pierre_10

    Unity Technologies

    Joined:
    Apr 1, 2016
    Posts:
    33
    I would personally go with schedulers where your opacity is tracked within your code. on first click, start a scheduler with a method that fades over time and store the opacity. on second click, look if the scheduler is running. If it is, do the other logic.
     
  3. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    Thank you for input! So you basically mean to animate opacity manually with scheduler and whenever I click to cancel previous animation and start new one from the beggining.
    When I think about it now is there other way to do this maybe using classes? If that was standard css it would be possible to set transition in class or pseudoclass and run it one sided. Or what if I would override transition duration and delay during the animation, would that be possible to move value to the start and restore default duration or something like that?