Hello, I’m new to scripting and I want to create a game like Diner Dash. How can I implement customer rotation around an array of chairs? I want the player to be able to shuffle the customers to different seats by clicking and dragging them, and then releasing the mouse click to place them in the desired seating position.
I’m not sure which part you’re struggling with, but the re-assignment logic would just be something like this:
Customer customerInTargetSeat = customers[targetSeat];
// Make the 'target' seat reference the dragged-and-dropped customer
customers[targetSeat] = draggedAndDroppedCustomer;
// Make the 'source' seat (once occupied by the dragged-and-dropped customer) reference the customer who originally occupied the 'target' seat
customers[sourceSeat] = customerInTargetSeat;```
You shouldn’t even need an array for this, each chair should just have a Chair class that holds a customer, the logic should be driven by the drag drop into a Customer
class.
I’ve already figured out how to swap chair positions between the customers.
Here is my code when grabbing customer:
var currentPosition = mouseWorldPosition - objectPosition;
int startIndex = (currentPosition.x > 0) ? 1 : 0;
for ( int i = 0; i < customerPrefabs.Count; i++ ) {
Debug.Log("startIndex: " + startIndex);
Debug.Log("i: " + i);
int chairIndex = (startIndex + i) % chairList.Length;
Debug.Log("chairIndex: " + chairIndex);
customerPrefabs*.transform.position = chairList[chairIndex].position;*
_customerPrefabs*.transform.rotation = chairList[chairIndex].rotation;*_
<em>_savedChair *= chairList[chairIndex];*_</em>
<em><em><em>savedPositions _= customerPrefabs*.transform.position;*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*```*_</em></em></em>
<em><em><em>_*Note: chairlist.length = 4*_</em></em></em>
<em><em><em>_*When my customerPrefab count is only 1, it can only swap positions between chairIndex 0 and 1. Why can't it go to 2 or 3? I calculated that when using modulus based on the chairList length, it can access from index 0 to last index chairList.*_</em></em></em>