I have tried with some delta positions, to adjust speed but unlucky. Have anyone some snipet of code for calculating speed?
EDIT (more info):
I have 4 animations
FIRST - idle
SECOND - is anim for gap for transition from FIRST TO THIRD animation, when we pull the object
THIRD - let’s say i have something to pull, and when it is pulled it is in idle, until it is pulled back, so call this animation IDLE PULL
FOURTH - is same as SECOND, just backwards because we pull back
So i need respetively change speed of animation in ration of speed of pulling . How to acheive this?
Here is my controller, i have bool isPulled, when it is true it goes to SECOND(PLAY ONCE) then to THIRD(LOOP) until it is uncheked, and when it is unchecked it goes to FOURTH(PLAY ONCE) and then again to idle
I am going to asume that what you want is simpli drag mouse along the screen Y-axis and not drag an image or object.
The following class is a controller, create an empty GameObject, call it whatever you like and add this component to it. The object will register the difference between the starting position of the drag and the end position of the drag to calculate the magnitude of the modifier.
After the calculations have been made the canvas child element will have to move / animate using the calculated modifier value. Multiply the value with the animation / movement speed that you have used for the animation / movement.
This is a sample of how it would be used :
using UnityEngine;
using UnityEngine.UI;
public class AnimatedUIElement : MonoBehaviour
{
public Canvas containingCanvas;
public float animationSpeed = 1f;
RectTransform rectTransform;
[SerializeField]
bool bAnimate = true;
void Start ()
{
rectTransform = GetComponent<RectTransform>();
}
void Update ()
{
if(bAnimate)
Animate();
}
void Animate ()
{
float animationDelta = Time.deltaTime * UIAnimationSpeedByDrag.Instance.animationDampingValue;
rectTransform.anchoredPosition = new Vector2(rectTransform.anchoredPosition.x + animationSpeed * animationDelta, rectTransform.anchoredPosition.y);
if(rectTransform.anchoredPosition.x > containingCanvas.pixelRect.width / 2)
{
rectTransform.anchoredPosition = new Vector2(-containingCanvas.pixelRect.width / 2, rectTransform.anchoredPosition.y);
}
}
}
There are many ways of optimizing this process. This will get you started if the context that i understood from your question is correct.