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. Dismiss Notice

Scrub animation using touch

Discussion in 'Scripting' started by _ahmedfawaz, Nov 10, 2017.

  1. _ahmedfawaz

    _ahmedfawaz

    Joined:
    Apr 5, 2013
    Posts:
    16
    Is it possible to scrub through an animation using touch? basically fast forwarding and rewinding the animation based on which direction your finger moves on the screen (x or -x)?.

    I've managed to achieve this using the mouse but it was a kind of hack tbh. I used a slider to control the animation time with
    Code (CSharp):
    1. anim["CameraPath"].normalizedTime = slider.value -= touchSpeed * Time.deltaTime;
    but i couldnt get this working with touch.

    any help is grealty appreciated, thanks.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,505
    Does the slider value change with touch? If it doesn't, is it just because you're missing an EventSystem in your scene?

    If the slider value changes, then the problem may actually be with that .normalizedTime property, which I have not personally used.

    What happens when you intentionally just "drive" the .normalizedTime property with a slowly-changing value, say perhaps (Time.time % 1.0f) or something?
     
  3. _ahmedfawaz

    _ahmedfawaz

    Joined:
    Apr 5, 2013
    Posts:
    16
    Im not trying to change the slider value with touch here, I was attempting to change the animation time by dragging my finger left or right. When I did use the slider I got it all to work using the mouse by dragging left or right.

    This is all quite beyond me to be honest I'm still quite new to coding in general.

    Do you recommend a way to get this done? I've been told to look at idraghandlers.