hey sorry if this has been asked I tried a search but was a bit overwhelmed with what came up and didn’t really pertain to what I was looking for
I am a noob to Unity and decided to try a shot at making “Space Invaders”
I am using C# here.
I want the enemy to reach a certain point then drop and reverse direction I did this code and well didn’t do what I thought it would.
I was thinking that multiplying by a negative number it would make it change direction but it just jumps it to the other side of the screen instead
public float EnemySpeed;
void Update()
{
float amountToMove = EnemySpeed * Time.deltaTime;
transform.Translate(Vector3.right * amountToMove);
if (transform.position.x >= 9.0f)
transform.position = new Vector3(transform.position.x * -1, transform.position.y - 1, transform.position.z);
else if (transform.position.x < -9.0f)
transform.position = new Vector3(transform.position.x * -1, transform.position.y - 1, transform.position.z);
}
would appreciate it if somebody could point me in the right direction
thanks