Yet another solution for movement, and a question about variable definitions

http://pastebin.com/5irprKdG

Things of interest (to me at least):

As Xianny did below, I used a direction variable (integer) to determine the direction.
I’ve done a lot of recfactoring into functions, which I hope helps with organization.

If I set enemySpeed within the declaration, the formation doesn’t move. If, instead, I set the speed in the Start() (as I’ve done here) everything works. Is there a reason for this?

1 Like

Nice approach for movement over there.

This behave with the enemySpeed happens because you have declared it as public, so it will always use the value that it have on the inspector instead of an value in the declaration (if you set is an public variable, the inspector value will be the first value that you have addressed in the declaration when you compiled the code for the first time). Whoever if you change it on runtime like you did in the start method, it will change the public variable since it is an event that happens after the declaration and after the inspector changes the value.

Privacy & Terms