- Home /
Question by
mrmeizongo · Mar 16, 2020 at 09:51 PM ·
2dcanvasrecttransform
Why does my code make the RectTransform move only along the Y coordinate?
I have this code below that takes a RectTransform as an argument and moves it to another position smoothly. However it only moves on the Y coordinate. Can somebody tell me what I'm doing wrong? I've been scratching my head over this for a while now.
float currentTime = 0;
float timeOfTravel = 3;
float normalized value = 1;
private IEnumerator LerpObject(RectTransform rectTransform)
{
while (currentTime <= timeOfTravel)
{
currentTime += Time.deltaTime;
normalizedValue = currentTime / timeOfTravel; // we normalize our time
rectTransform.anchoredPosition = Vector3.Lerp(rectTransform.anchoredPosition, new Vector3(3840, 80, 0), normalizedValue);
yield return null;
}
}
Comment
Your answer
Follow this Question
Related Questions
Scale 2d Sprite collider size to UIImage collider size 0 Answers
Change Text Scale on a Canvas Child from a script. 1 Answer
Looking for picture in picture effect using Canvas Elements and Cinemachine follow target 0 Answers
Change position of a text prefab added to a world space canvas via scripting 0 Answers