edutainPeople edutainPeople - 1 month ago 9x
C# Question

Unity: Moving a sprite to coordinate (tween)

I'm new to Unity C#, and have tried to get a simple sprite to move to i.e. coordinates 3,5 ; 4,5. I cannot make this work.

Any help will be highly appreciated.

I have tried the following:

public class Zookeeper : MonoBehaviour {

public float speed = 50f;
private Vector2 target;

void Start () {
target = transform.position;

void Update () {
transform.position = Vector2.MoveTowards(
transform.position, target, speed * Time.deltaTime


Just change the Start method to something like this:

    void Start () 
        target = new Vector2(3.5f, 4.5f);

You need to operate with target to make it move where you want.