6 using System.Collections;
7using System.Collections.Generic;
18 private float cardMoveSpeed = 8f;
20 private float buttonCooldownTime = 0.125f;
22 private int cardZMultiplier = 32;
24 private bool useDefaultUsedXPos =
true;
26 private int usedCardXPos = 1280;
28 private Transform[] cards =
null;
30 private int cardArrayOffset;
31 private Vector3[] cardPositions;
32 private int xPowerDifference;
42 xPowerDifference = 9 - cards.Length;
46 if (useDefaultUsedXPos)
48 int cardWidth = (int)(cards[0].GetComponent<RectTransform>().rect.width);
49 usedCardXPos = (int)(Screen.width * 0.5f + cardWidth);
52 cardPositions =
new Vector3[cards.Length * 2 - 1];
55 for (
int i = cards.Length; i > -1; i--)
57 if (i < cards.Length - 1)
59 cardPositions[i] =
new Vector3(-Mathf.Pow(2, i + xPowerDifference) + cardPositions[i + 1].x, 0, cardZMultiplier * Mathf.Abs(i + 1 - cards.Length));
63 cardPositions[i] = Vector3.zero;
68 for (
int i = cards.Length; i < cardPositions.Length; i++)
70 cardPositions[i] =
new Vector3(usedCardXPos + 4 * (i - cards.Length), 0, -2 + -2 * (i - cards.Length));
79 if (Input.GetAxisRaw(
"Horizontal") < 0 && cardArrayOffset > 0)
82 StartCoroutine(ButtonCooldown());
84 else if (Input.GetAxisRaw(
"Horizontal") > 0 && cardArrayOffset < cards.Length - 1)
87 StartCoroutine(ButtonCooldown());
92 for (
int i = 0; i < cards.Length; i++)
94 cards[i].localPosition = Vector3.Lerp(cards[i].localPosition, cardPositions[i + cardArrayOffset], Time.deltaTime * cardMoveSpeed);
95 if (Mathf.Abs(cards[i].localPosition.x - cardPositions[i + cardArrayOffset].x) < 0.01f)
97 cards[i].localPosition = cardPositions[i + cardArrayOffset];
100 if (cards[i].localPosition.x == 0)
102 cards[i].gameObject.GetComponent<CanvasGroup>().interactable =
true;
106 cards[i].gameObject.GetComponent<CanvasGroup>().interactable =
false;
113 IEnumerator ButtonCooldown()
116 yield
return new WaitForSeconds(buttonCooldownTime);
static bool canUseHorizontalAxis
Credit Erdener Gonenc - @PixelEnvision.