- Home /
Question by
imLor · Oct 18, 2021 at 02:01 PM ·
2d-physics2d-gameplay
How to postpone the action of the command | Translate | for a few seconds in Update?
I've tried everything with | Invoke | it doesn't work that way.Can you tell me something please !
Vector3 vector3 ;
public float x;
void Update ()
{
vector3.x = x;
transform.Translate(vector3 * Time.deltaTime) ;
}
Comment
Best Answer
Answer by sztobar · Oct 18, 2021 at 02:12 PM
I'm not sure how to want/need to call the action. Can you provide more context?
You can try with this:
Vector3 vector3 ;
public float x;
private bool isInvoked;
public void PostponeTranslate() // <- call this to apply translate after a specific delay
{
float timeToPostpone = 2f;// <- set here any time you need/want
Invoke("SetIsInvoked", timeToPostpone);
}
void SetIsInvoked()
{
isInvoked = true;
}
void Update ()
{
if (isInvoked)
{
vector3.x = x;
transform.Translate(vector3 * Time.deltaTime) ;
}
}
Answer by swanne · Oct 18, 2021 at 02:49 PM
It's not clear what you are trying to achieve, but I find coroutines a very good way to handle postponing or delaying code / instructions.
Your answer

Follow this Question
Related Questions
why player jumps forever 2 Answers
Enemy is moving opposite of the player 2D 1 Answer
Trying to implement a parry mechanic 0 Answers
Adding knockback to a 2D game (in C#) 2 Answers
How do instantiate a ghost prefab when the player dies? 2 Answers