samedi 8 août 2020

Two objects sharing one random script spawn the same order when they should spawn different orders

I have two "customer" objects that share an Order Manager script in Unity. Ideally, every time a customer needs to create a new order, it should be different than the last one. What happens instead is that customer 1 orders X and Y, and then customer 2 will order X and Y instead of Z (or whichever different combination). When the script is placed on just one customer instead of 2, the random order function works correctly. There are no static variables.

To add, if I clear customer 1's order, the next order is different. Customer 2's orders will still follow customr 1. Ex: Customer 1 has 2 orders: X X, then Y Y Customer 2 won't start at the second order, it will order the same way: X X, then Y Y

This is the method that's causing an issue:

   IEnumerator CustomerOrder(bool status, float delayTime)
{
  yield return new WaitForSeconds(delayTime);//delay between orders
 imageOffset.y = -0.75f;//space between order visuals
 numberOfOrderItems = rnd.Next(1, maxOrderNumber + 1);//between 1 and 3 items per order  
 customerOrder = new GameObject[numberOfOrderItems];// order collection
 Instantiate(orderBackgrounds[numberOfOrderItems - 1], orderVisual.transform);//Spawn correct background for number of items
 for (int x = 0; x < numberOfOrderItems; x++)
 {
     int y = rnd.Next(products.Length);//choose a random number representing an index in the products array
     customerOrder[x] = Instantiate(productImages[y],
     orderVisual.transform.position + imageOffset,
     Quaternion.identity,
     orderVisual.transform);//spawn a visual representation of the order
     imageOffset.y += -0.95f;//places next order visual lower
 }
 
 makingOrder = false;//we've finished making the order
}



Aucun commentaire:

Enregistrer un commentaire