- Home /
Question by
SCIIBAJAN · Aug 14, 2021 at 05:24 PM ·
2d2d spritesmoving
How can i move object from one point to another point several times? (2d sprite)
Hello. I have an object. I need to move it from one point to another. In script it looks so:
private void FixedUpdate()
{
Move(0.5f, 1f, _SubjectsRegulatory.speedSubjects); //x, y, speed
}
private bool _isPointSetted = false;
protected void Move(float x, float y, float speed)
{
bool isGetPoint = false;
if (_isPointSetted == false)
{
_endPoint = PositionToMove(x, y);
_isPointSetted = true;
}
if (isGetPoint == false)
{
Moving(speed);
FinishedMove(ref isGetPoint);
}
}
protected void FinishedMove(ref bool isGetPoint)
{
if (_endPoint == (Vector2)transform.position)
{
isGetPoint = true;
}
}
protected void Moving(float speed)
{
transform.position = Vector2.MoveTowards(transform.position, _endPoint, speed * Time.fixedDeltaTime);
}
So, what is the problem. When i want to move object to one point and then i want to move the object to another point, it doesnt work. I show you what i try to do:
void FixedUpdate()
{
Move(0.5f, 1f, _SubjectsRegulatory.speedSubjects); //x, y, speed
Move(10f, 1f, _SubjectsRegulatory.speedSubjects);
}
I tried to use loop while in method Move(), but it still did`nt wotk. I just need to call function Move(), and when it stopped i need to call next function Move(). They work the same time but i need they to work in turn. Sorry for English. Who can speak Russian or Ukrainian write please
Comment