- Home /
Question by
Unity_SA · Dec 28, 2017 at 12:50 AM ·
scripting problembuttonif-statementsfixedupdate
If statement inside FixedUpdate
I have a bool that I change from another script. It's named enemiesMove. I want my enemies to move when it is true, but when it is true, nothing happens. This is the bit of script I've been working with.
public EnemySpawnScript enemySpawnScript;
private void FixedUpdate()
{
Vector3 playerV3 = playerT.position;
if (enemySpawnScript.enemiesMove == true)
{
transform.position = Vector2.MoveTowards(transform.position, playerV3, speed * Time.deltaTime);
}
I assigned the script in the Editor because its easier. The bool gets changed in that script.
Thanks in advance!
edit: Turns out my speed was'nt set. I ended up using this though, if it helps anyone.
private void FixedUpdate()
{
if (playermovement.enemiesMove == true)
{
Vector3 playerV3 = playerT.position;
transform.position = Vector3.MoveTowards(transform.position, playerV3, speed * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Is there a thing like a type of a script? 3 Answers
Central score counter for 3 score generating buttons 1 Answer
Image texture not visible when loaded in script, and button placement wrt image 0 Answers
Hey! I need help. With visual scripting BOLT 0 Answers
Why my 'if' condition is not working 1 Answer