K
K
kyryliukbogdan2020-03-30 18:16:25
2D
kyryliukbogdan, 2020-03-30 18:16:25

How to make an object move along certain coordinates?

Hello, I want to make the movement of the game object along the given coordinates, namely: so that the object moves to the coordinate for example 1; 0 from the coordinate 0; 0, and then when it reaches this coordinate, it moves vice versa to the initial coordinate 0; 0, and so constantly like opponents in mario. I made the object move to the given coordinate, but I can't make the object move backwards and put it all in a loop. Here is the code:

public class blockmove : MonoBehaviour
{
    void Update()
    {
        gameObject.transform.position = new Vector2(gameObject.transform.position.x + 2 * Time.deltaTime, gameObject.transform.position.y);
    }
}

5e820d369f630050187261.png
this is how i want to do it please help me

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DanielMcRon, 2020-03-30
@kyryliukbogdan

Vector3.MoveTowards - movement to the object
When reached, check the point and set the true flag, and back, and so constantly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question