I've searched everywhere for this answer but everything I find is in Javascript and a lot of it doesn't help/work in my situation since most of it is Vector3's and using each axis, and my game is 2D.
So I have these prefabs that get spawned off-screen and then I have a script attached to them that tells them to move left on the x axis. I need them to also pick a random direction (up or down) on the y axis, and travel that way until they get to a certain spot (range) and then to switch directions and go the opposite etc.
Here is what I have tried most recently:
public float itemUp = 0.1f;
public float itemMove = 0.7f;
public float x;
float y;
float z;
Vector3 pos;
void Update () {
//transform.position = Vector2(Random.Range (1,4),Random.Range (1,4),10);
transform.position -= Vector3.right * itemMove * Time.deltaTime;
x = 0;
y = Random.Range(-100, 100);
z = 0;
pos = new Vector3(-x, y, z);
transform.position = pos * itemUp * Time.deltaTime;
}
Anyone know what I'm missing/not doing correctly? I'd really appreciate any help you can give, thank you.