Hi,
lets assume i have a list called objectT. How to randomly move object in z or x in 5 ways (left, right, front, back or stay in place you are) but the objects at position z and x cannot go over 10 or -10, they have to be between 10 and -10 in both z and x. Also there should be not more than 3 object at the same place.
switch(Random.Range(1,5)){
case 1: // move x
object.x = Random.Range(-10,10);
break;
case 2: // move y
object.y = Random.Range(-10,10);
break;
//Etc, do this for every direction
}
Putting the random 1-5 in the switch statement lets you specify what happens if each number is called. There, I made it move randomly from -10 to 10 in x if 1 was called, then if 2 was called I made it move by y. You can set all 5 directions this way, and just alter the movement code.
Thanks, why i always forget that switch exist xD I always torture myself using if why i can use switch. Also i din’t think of puting the Random.Range in the drection but i used it to get the one of the if. I need more practice because i stil forget that i just could use that.
Thanks very much. Let god will reward you in children.
Now something more difficult.
What if object start at position of 5.5f,0.0f,5.5f. Then i might move in one of four direction by 1 unit but only if that direction do not exceed -10 or 10. If it do then i will move somewhere else, but there cannot be more than 3 object at the same place.