I want to decide if the speed will be randomly or constant.
In the top of script:
[Header("Speed")]
public float constantSpeed;
public float minRandomSpeed, maxRandomSpeed;
public bool randomSpeed = false;
In Start:
private void Start()
{
RandomSpeed();
}
In Update
private void Update()
{
RandomSpeed();
}
RandomSpeed:
private void RandomSpeed()
{
for (int i = 0; i < instancesToMove.Length; i++)
{
if (randomSpeed)
{
movementSpeeds[i] = Random.Range(minRandomSpeed, maxRandomSpeed);
}
else
{
movementSpeeds[i] = constantSpeed;
}
}
}
The problem is in the RandomSpeed if randomSpeed is true it will keep giving the movementSpeeds each frame a new random values. But I want that when randomSpeed is true give movementSpeeds new speed values only once. Then if I will set the randomSpeed false then true again then give again new random speed values.