I am making 2D unity code where I put a random x value and get a gameobject to slowly move to that position. I cant use += or -= because the number can be larger or smaller than the vector. how do I fix this? here is the code.
public IEnumerator fistthrust()
{
float leftpos = Random.Range(-8, 8);
float rightpos = Random.Range(-8, 8);
while (fist.transform.position.x != leftpos && rightfist.transform.position.x != rightpos)
{
fist.transform.position = new Vector3(leftpos, 0, 0); -- fix these
rightfist.transform.position = new Vector3(rightpos, 0, 0); -- 2 lines
}
fistscr.down();
yield return new WaitForSeconds(0.5f);
rfistscr.down();
fistscr.up();
yield return new WaitForSeconds(0.5f);
rfistscr.up();
fistscr.rest();
yield return new WaitForSeconds(0.5f);
rfistscr.rest();
}
I am a beginner game designer and have no idea what to try or what to do. Please help!!