- Home /
Question by
Bhargav5530 · Sep 10, 2015 at 06:16 PM ·
movementmove an objectrecttransformmovetowardsvector3.movetowards
MoveTowards is not working with RectTransform component
Hello guys,
I am stuck with RectTransform component. I want to use Vector2.MoveTowards() function in my game. The problem is i am using RectTransform component. The same script is work with Transform component but it is not working with RectTransform component.
Here is my code
using UnityEngine;
using System.Collections;
public class MoveSlider : MonoBehaviour {
Vector2 start,target;
public RectTransform slider;
void Start(){
start = new Vector2 (slider.anchoredPosition.x, slider.anchoredPosition.y);
target = new Vector2 (slider.anchoredPosition.x-50f, slider.anchoredPosition.y-50f);
}
void Update(){
slider.localPosition = Vector2.MoveTowards (start, target, Time.deltaTime);
}
}
In my above code I can print the start and target value in debug but I cant get a movement.
Do you have any idea why it is not working. here slider is my gameobject with RectTransform component in UI Canvas. the script is attach to camera and I am referencing slider to MoveSlider script.
Need any kind of help..
Comment