Search Unity

How to use Easy Touch on Tetris game?

Discussion in 'Scripting' started by pokeking, Jul 16, 2015.

  1. pokeking

    pokeking

    Joined:
    May 13, 2015
    Posts:
    42
    Hi everyone, i found a script code for a Tetris game, but it moves the objects by button.
    I want to control by swipe on the screen (use Easy Touch or Easy Button), but i don't know how to code and replace it in the old script :(
    please help, here the code
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. // Don't use "System.Collections.Generic" if you want to export your app to flash
    6.  
    7. public class Tetrimo : MonoBehaviour {
    8.     #region Shapes and Colors
    9.     static Vector2[, ,] Shapes = new Vector2[7,4,4] {
    10.         // #
    11.         // ###
    12.         {
    13.             {new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0) },
    14.             {new Vector2(0, 1), new Vector2(1, 1), new Vector2(0, 0), new Vector2(0,-1) },
    15.             {new Vector2(0, 1), new Vector2(1, 1), new Vector2(2, 1), new Vector2(2, 0) },
    16.             {new Vector2(1, 1), new Vector2(1, 0), new Vector2(1,-1), new Vector2(0,-1) },
    17.         },
    18.         //   #
    19.         // ###
    20.         {
    21.             {new Vector2(2, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0)},
    22.             {new Vector2(0, 1), new Vector2(0, 0), new Vector2(0,-1), new Vector2(1,-1)},
    23.             {new Vector2(0, 1), new Vector2(1, 1), new Vector2(2, 1), new Vector2(0, 0)},
    24.             {new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0), new Vector2(1,-1)}
    25.         },
    26.         //  #
    27.         // ###
    28.         {
    29.             {new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0)},
    30.             {new Vector2(0, 1), new Vector2(0, 0), new Vector2(0,-1), new Vector2(1, 0)},
    31.             {new Vector2(0, 1), new Vector2(1, 1), new Vector2(2, 1), new Vector2(1, 0)},
    32.             {new Vector2(0, 0), new Vector2(1, 1), new Vector2(1, 0), new Vector2(1,-1)}
    33.         },
    34.         // ##
    35.         // ##
    36.         {
    37.             {new Vector2(0, 1), new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0)},
    38.             {new Vector2(0, 1), new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0)},
    39.             {new Vector2(0, 1), new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0)},
    40.             {new Vector2(0, 1), new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0)}
    41.         },
    42.         //
    43.         // ####
    44.         {
    45.             {new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0), new Vector2(3, 0)},
    46.             {new Vector2(0, 1), new Vector2(0, 0), new Vector2(0,-1), new Vector2(0,-2)},
    47.             {new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0), new Vector2(3, 0)},
    48.             {new Vector2(0, 1), new Vector2(0, 0), new Vector2(0,-1), new Vector2(0,-2)}
    49.         },                                                                        
    50.         //  ##                                                                    
    51.         // ##                                                                      
    52.         {                                                                          
    53.             {new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(2, 1)},
    54.             {new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1,-1)},
    55.             {new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(2, 1)},
    56.             {new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1,-1)}
    57.         },                                                                        
    58.         // ##                                                                      
    59.         //  ##                                                                    
    60.         {                                                                          
    61.             {new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0), new Vector2(2, 0)},
    62.             {new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(0,-1)},
    63.             {new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0), new Vector2(2, 0)},
    64.             {new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(0,-1)}
    65.         }
    66.     };
    67.     static Color[] Colors = new Color[7] {
    68.         Color.red,
    69.         Color.green,
    70.         Color.blue,
    71.         Color.white,
    72.         Color.yellow,
    73.         Color.magenta,
    74.         Color.cyan
    75.     };
    76.     #endregion
    77.     #region NestedTypes
    78.     public struct CFieldSize {
    79.         public int Left, Right, Bottom, Top;
    80.     }
    81.     /// <summary>
    82.     /// <list type="">
    83.     ///     <item>Falling</item>
    84.     ///     <item>Landed </item>
    85.     ///     <item>Fixed< /item>
    86.     /// </list>
    87.     /// </summary>
    88.     public enum TetrimoState {
    89.         Spawning,   // Tetrimo is about to become "Falling"
    90.         Falling,
    91.         Landed,
    92.         Fixed,
    93.         Preview
    94.     }
    95.     #endregion
    96.  
    97.     #region Class instances data members
    98.     /// <summary>All tetrimos in Preview State</summary>
    99.     public static Tetrimo NextTetrimo;
    100.     public static uint TetrimoCount = 1;
    101.     /// <summary>border position of the game field (inclusive values)</summary>
    102.     static CFieldSize FieldSize = new CFieldSize() {
    103.         Left    =   0,
    104.         Right   =  10,
    105.         Top     =  18,  // always start at top-1, cause the center of each tetrimo is the second element on the lower row
    106.         Bottom  =   0
    107.     };
    108.     /// <summary>Start position of new Tetrimos in 'Preview' state</summary>
    109.     static Vector2 PreviewHUD = new Vector2() {
    110.         x = 16,
    111.         y = 16
    112.     };
    113.     /// <summary>
    114.     /// <list type="">
    115.     ///     <item>null,         if position is free</item>
    116.     ///     <item>gameObject,   if position is occupied </item>
    117.     /// </list>
    118.     /// </summary>
    119.     static GameObject[,] FieldMatrix = new GameObject[19, 11];
    120.     #endregion
    121.  
    122.     #region Fields (Set in Unity Editor)
    123.     /// <summary>Pointer to itselfs => create new Tetrimos</summary>
    124.     public GameObject   TetrimoPrefab;
    125.     public GameObject   TetrimoPartPrefab;
    126.     public GameObject   TetrimoExplosionPrefab;
    127.     public GameObject   FourLinesLabelPrefab;
    128.  
    129.     public TetrimoState State;
    130.     /// <summary>Swap action cooldown</summary>
    131.     public float        SwapCooldown;
    132.     /// <summary>Horizontal movement speed</summary>
    133.     public float        HorizontalSpeed;
    134.     public float        FallingCooldown;
    135.     public float        FallingSpeed;
    136.     #endregion
    137.  
    138.     #region Private Fields
    139.     /// <summary>Countdown for next swap</summary>
    140.     float NextSwap = 0.0f;
    141.     /// <summary>Countdown for next fall</summary>
    142.     float NextFall;
    143.     int   ShapeIndex, RotationIndex;
    144.     bool  IsMovingHorizontal = false;
    145.     #endregion
    146.  
    147.     #region Properties
    148.     bool CanMoveDown {
    149.         get {
    150.             if(IsMovingHorizontal)
    151.                 return false;
    152.  
    153.             foreach (Transform child in transform) {
    154.                 if (Mathf.RoundToInt(child.position.y - 1) < 0 || FieldMatrix[Mathf.RoundToInt(child.position.y - 1), Mathf.RoundToInt(child.position.x)] != null)
    155.                     return false;
    156.             }
    157.             return true;
    158.         }
    159.     }
    160.     bool CanMoveRight {
    161.         get {
    162.             bool canMoveRight = true;
    163.             foreach (Transform child in transform) {
    164.                 canMoveRight &= Mathf.RoundToInt(child.position.x + 1) <= Tetrimo.FieldSize.Right && FieldMatrix[Mathf.RoundToInt(child.position.y), Mathf.RoundToInt(child.position.x + 1)] == null;
    165.             }
    166.             return canMoveRight;
    167.         }
    168.     }
    169.     bool CanMoveLeft {
    170.         get {
    171.             bool canMoveLeft = true;
    172.             foreach (Transform child in transform) {
    173.                 canMoveLeft &= Mathf.RoundToInt(child.position.x - 1) >= Tetrimo.FieldSize.Left && FieldMatrix[Mathf.RoundToInt(child.position.y), Mathf.RoundToInt(child.position.x - 1)] == null;
    174.             }
    175.             return canMoveLeft;
    176.         }
    177.     }
    178.     bool CanRotate {
    179.         get {
    180.             // Iterate through each TetrimoParts
    181.             for (int index = 0; index < Shapes.GetLength(2); index++) {
    182.                 Vector2 tmp = new Vector2(transform.position.x, transform.position.y) + Shapes[ShapeIndex, (RotationIndex + 1) % Shapes.GetLength(2), index];
    183.  
    184.                 if (tmp.x < FieldSize.Left || tmp.x > FieldSize.Right || tmp.y < FieldSize.Bottom || tmp.y > FieldSize.Top)
    185.                     return false;
    186.  
    187.                 if (FieldMatrix[Mathf.RoundToInt(tmp.y), Mathf.RoundToInt(tmp.x)] != null)
    188.                     return false;
    189.             }
    190.             return true;
    191.         }
    192.     }
    193.     #endregion
    194.  
    195.     #region Event Handler
    196.     void Start () {
    197.         switch (State) {
    198.         case TetrimoState.Spawning:
    199.             NextFall = FallingCooldown;
    200.  
    201.             // Create shape and translate it at the center top of the game field.
    202.             // REMARK: Do not use translate here! Instantiate create a copy of the current object.
    203.             CreateShape();
    204.             transform.position = new Vector3((int)(FieldSize.Right / 2), FieldSize.Top - 1, 0);
    205.  
    206.             // Check if the player has lost the game
    207.             foreach (Transform child in transform) {
    208.                 if (FieldMatrix[(int)child.position.y, (int)child.position.x] != null) {
    209.                     Application.LoadLevel("GameOver");
    210.                 }
    211.             }
    212.             name = "Tetrimo#" + (TetrimoCount-1);
    213.             State = TetrimoState.Falling;
    214.             break;
    215.  
    216.         case TetrimoState.Preview:
    217.             RotationIndex = Random.Range(0, Shapes.GetLength(1));
    218.             ShapeIndex    = Random.Range(0, Shapes.GetLength(0));
    219.             CreateShape();
    220.             transform.position = new Vector3(PreviewHUD.x, PreviewHUD.y);
    221.  
    222.             NextTetrimo = this;
    223.  
    224.             TetrimoCount++;
    225.             name = "Tetrimo#" + TetrimoCount;
    226.             break;
    227.         }
    228.     }
    229.     void Update() {
    230.         if (State != TetrimoState.Fixed && State != TetrimoState.Preview && State != TetrimoState.Spawning) {
    231.             if (State != TetrimoState.Landed && Input.GetAxis("Vertical") < 0)
    232.                 StartCoroutine(FallingDown());
    233.  
    234.             if (Input.GetButtonDown("Horizontal"))
    235.                 StartCoroutine(MoveHorizontal());
    236.  
    237.             // Set "up" as alternative button for Jump (Project => Input)
    238.             if ((Input.GetButton("Jump")) && Time.time > NextSwap) {  
    239.                 if (this.CanRotate) {
    240.                     StartCoroutine(RotateTetrimo());
    241.                     NextSwap = Time.time + SwapCooldown;
    242.                 }
    243.             }
    244.  
    245.             // Automatic falling down
    246.             if (NextFall < 0) {
    247.                 StartCoroutine(FallingDown());
    248.                 NextFall = FallingCooldown;
    249.             }
    250.             NextFall -= FallingSpeed * Time.deltaTime;
    251.         }
    252.  
    253.         if (State == TetrimoState.Preview) {
    254.             transform.Rotate(0, 1f, 0, Space.World);
    255.         }
    256.  
    257.         // Debugging Feature
    258.         if (Input.GetKeyDown(KeyCode.F2)) {
    259.             KillAndReload();
    260.         }
    261.     }
    262.     #endregion
    263.  
    264.     #region Coroutines: http://unitygems.com/coroutines/
    265.     /// <summary>
    266.     /// Active the Tetrimo in the preview hub
    267.     /// </summary>
    268.     /// <returns></returns>
    269.     IEnumerator ActivateTetrimoInPreview() {
    270.         yield return 0;
    271.     }
    272.     /// <summary>
    273.     /// Create a new Tetrimo and place it in the preview hub.
    274.     /// </summary>
    275.     /// <returns></returns>
    276.     IEnumerator CreatePreviewStateTetrimo() {
    277.         yield return 0;
    278.     }
    279.     IEnumerator MoveHorizontal() {
    280.         IsMovingHorizontal = true;
    281.  
    282.         float moved     = 0.0f;
    283.         float direction = Input.GetAxis("Horizontal");
    284.  
    285.         if ((this.CanMoveRight && direction > 0) || (this.CanMoveLeft && direction < 0)) {
    286.             while (moved <= 1.0f) {
    287.                 float moveStep = Mathf.Min(HorizontalSpeed * Time.deltaTime, 1.1f - moved);   // 1.1f since float has some rounding problems!
    288.  
    289.                 if (direction > 0)
    290.                     transform.Translate(Vector3.right * moveStep, Space.World);
    291.                 else if (direction < 0)
    292.                     transform.Translate(Vector3.left  * moveStep, Space.World);
    293.  
    294.                 moved += moveStep;
    295.                 yield return 0;
    296.             }
    297.  
    298.             // We will correct the actual position of each stone when it landed
    299.             transform.position = new Vector2(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.y));
    300.         }
    301.  
    302.         IsMovingHorizontal = false;
    303.     }
    304.     IEnumerator FallingDown() {
    305.         if (this.CanMoveDown) {
    306.             transform.Translate(Vector3.down, Space.World);
    307.         }
    308.         else {
    309.             if (State == TetrimoState.Falling) {
    310.                 // After the Tetrimo has landed, the player can move it in the first 400ms.
    311.                 this.audio.Play();
    312.                 State = TetrimoState.Landed;
    313.                 yield return new WaitForSeconds(0.4f);
    314.                 while (IsMovingHorizontal)  // Wait for end of possible MoveHorizontal - calls
    315.                     yield return new WaitForEndOfFrame();
    316.  
    317.                 if (this.CanMoveDown) {
    318.                     State = TetrimoState.Falling;
    319.                 }
    320.                 else {
    321.                     State = TetrimoState.Fixed;
    322.                     foreach (Transform child in transform) {
    323.                         Tetrimo.FieldMatrix[Mathf.RoundToInt(child.position.y), Mathf.RoundToInt(child.position.x)] = child.gameObject;
    324.                     }
    325.                     ArrayList lines = FindLines();
    326.  
    327.                     if (lines.Count > 0) {
    328.                         int FourLineBonus = 0;
    329.  
    330.                         // Destruction animation
    331.                         foreach (int line in lines) {
    332.                             int y = Mathf.CeilToInt(line);
    333.  
    334.                             for (int i = FieldSize.Left; i <= FieldSize.Right; i++) {
    335.                                 Instantiate(TetrimoExplosionPrefab, FieldMatrix[y, i].transform.position, Quaternion.identity);
    336.                                 Destroy(FieldMatrix[y, i]);
    337.                                 FieldMatrix[y, i] = null;
    338.                             }
    339.                         }
    340.                         if (lines.Count == 4) {
    341.                             FourLineBonus = FieldMatrix.GetLength(1);
    342.                             Instantiate(FourLinesLabelPrefab, new Vector3(transform.position.x, transform.position.y + 1.0f), Quaternion.identity);
    343.                         }
    344.  
    345.                         // update logic
    346.                         yield return new WaitForEndOfFrame();
    347.                         lines.Sort();
    348.                         lines.Reverse();
    349.                         foreach (int line in lines) {
    350.                             if (line >= FieldSize.Top)
    351.                                 continue;
    352.                             LetLinesAboveFalling(line + 1);
    353.                         }
    354.  
    355.                         // adding scores
    356.                         MatchCamera.Scores += FieldMatrix.GetLength(1) * lines.Count + MatchCamera.Continuous + FourLineBonus;
    357.                         MatchCamera.Continuous++;
    358.  
    359.                         // check if next level has been reached
    360.                         if (MatchCamera.Scores >= MatchCamera.Level * MatchCamera.ScoresForNextLevel) {
    361.                             MatchCamera.Level = 1 + Mathf.FloorToInt(((float)MatchCamera.Scores) / MatchCamera.ScoresForNextLevel);
    362.                             FallingSpeed++;
    363.                         }
    364.                     }
    365.                     else {
    366.                         MatchCamera.Continuous = 0;
    367.                     }
    368.  
    369.                     // Create the new Tetrimo as previewed by destroying the previewed Tetrimo, and place a new created Tetrimo
    370.                     // yield return new WaitForSeconds(0.5f);
    371.                     ActivateAndCreateNewPreview();
    372.  
    373.                     // Extract children (TetrimoParts) from Tetrimo. We will delete the Tetrimo itself.
    374.                     Transform[] children = GetComponentsInChildren<Transform>();
    375.                     for (int i = 0; i < children.Length; i++)
    376.                         children[i].parent = null;
    377.                     Destroy(gameObject);
    378.                 }
    379.             }
    380.         }
    381.     }
    382.  
    383.     void ActivateAndCreateNewPreview() {
    384.         GameObject newGameObject = (GameObject)Instantiate(TetrimoPrefab, Vector3.zero, Quaternion.identity);
    385.         Tetrimo newFallingTetrimo       = newGameObject.GetComponent<Tetrimo>();
    386.         newFallingTetrimo.RotationIndex = NextTetrimo.RotationIndex;
    387.         newFallingTetrimo.ShapeIndex    = NextTetrimo.ShapeIndex;
    388.         newFallingTetrimo.State         = TetrimoState.Spawning;
    389.  
    390.         foreach (Transform child in newFallingTetrimo.transform) {
    391.             Destroy(child.gameObject);
    392.         }
    393.         Destroy(NextTetrimo.gameObject);
    394.  
    395.         newGameObject = (GameObject)Instantiate(TetrimoPrefab, Vector3.zero, Quaternion.identity);
    396.         Tetrimo newPreviewTetrimo = newGameObject.GetComponent<Tetrimo>();
    397.         newPreviewTetrimo.State = TetrimoState.Preview;
    398.     }
    399.     IEnumerator RotateTetrimo() {
    400.         this.audio.Play();
    401.  
    402.         foreach (Transform child in transform) {
    403.             Destroy(child.gameObject);
    404.         }
    405.  
    406.         RotationIndex = (RotationIndex + 1) % Shapes.GetLength(2);
    407.         CreateShape();
    408.         yield return 0;
    409.     }
    410.     void LetLinesAboveFalling(float lineToBegin) {
    411.         int bottom = Mathf.RoundToInt(lineToBegin);
    412.  
    413.         for (int y = bottom; y <= FieldSize.Top; y++) {
    414.             for (int x = FieldSize.Left; x <= FieldSize.Right; x++) {
    415.                 FieldMatrix[y-1, x] = FieldMatrix[y, x];
    416.                 if (FieldMatrix[y-1, x] != null)
    417.                     FieldMatrix[y-1, x].transform.Translate(Vector3.down);
    418.  
    419.                 FieldMatrix[y, x] = null;
    420.             }
    421.         }
    422.     }
    423.     #endregion
    424.  
    425.     #region Helper functions
    426.     void CreateShape() {
    427.         foreach (Transform child in transform) {
    428.             Destroy(child.gameObject);
    429.         }
    430.  
    431.         for (int index = 0; index < Shapes.GetLength(2); index++) {
    432.             GameObject tmp = (GameObject)Instantiate(TetrimoPartPrefab, Shapes[ShapeIndex, RotationIndex, index], Quaternion.identity);
    433.  
    434.             tmp.transform.Translate(transform.position);
    435.             tmp.transform.parent = gameObject.transform;
    436.             tmp.renderer.material.color = Colors[ShapeIndex];
    437.         }
    438.     }
    439.     /// <summary>
    440.     /// Check matrix for full filled lines, where the current Tetrimo is part of it.
    441.     /// </summary>
    442.     /// <returns>y-indices of type int</returns>
    443.     ArrayList FindLines() {
    444.         ArrayList lines = new ArrayList();
    445.         Hashtable open  = new Hashtable(); // Never use classes or methods, that aren't listened in the Unity reference, if you aim for cross-plattform-support.
    446.  
    447.         foreach (Transform child in transform) {
    448.             int line = Mathf.CeilToInt(child.position.y);
    449.             if(!open.ContainsKey(line))
    450.                 open.Add(line, line);
    451.         }
    452.  
    453.         foreach (int y in open.Keys) {
    454.             bool fullline = true;
    455.             for (int i = FieldSize.Left; i <= FieldSize.Right; i++)
    456.                 fullline &= FieldMatrix[Mathf.RoundToInt(y), i] != null;
    457.             if (fullline)
    458.                 lines.Add((int) y);
    459.         }
    460.         return lines;
    461.     }
    462.     #endregion
    463.  
    464.     #region Debugging helper function
    465.     private void KillAndReload() {
    466.         for (int c = FieldSize.Left; c <= FieldSize.Right; c++) {
    467.             for (int r = FieldSize.Bottom; r <= FieldSize.Top; r++) {
    468.                 if (FieldMatrix[r, c] != null) {
    469.                     Destroy(FieldMatrix[r, c]);
    470.                 }
    471.             }
    472.         }
    473.         Tetrimo[] gameObjects = GetComponents<Tetrimo>();
    474.         foreach (Tetrimo go in gameObjects) {
    475.             if (go.State == TetrimoState.Falling)
    476.                 continue;
    477.  
    478.             Destroy(go.gameObject);
    479.         }
    480.  
    481.         for (int c = FieldSize.Left; c <= FieldSize.Right; c++) {
    482.             for (int r = FieldSize.Bottom; r <= FieldSize.Top; r++) {
    483.                 if (FieldMatrix[r, c] != null) {
    484.                     FieldMatrix[r, c] = (GameObject) Instantiate(TetrimoPartPrefab, new Vector2(c,r), Quaternion.identity);
    485.                     FieldMatrix[r, c].renderer.material.color = Color.white;
    486.                 }
    487.             }
    488.         }
    489.     }
    490.     #endregion
    491. }
    492.  
     
    Last edited: Jul 16, 2015
  2. pokeking

    pokeking

    Joined:
    May 13, 2015
    Posts:
    42
    please help :(
     
  3. pokeking

    pokeking

    Joined:
    May 13, 2015
    Posts:
    42
  4. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    First you should check some tutorials about touch and also the API: http://docs.unity3d.com/ScriptReference/Touch.html
    You should try it yourself replacing it or show your script you have tried to make so people can help you. Most of the time, members of this forum don't write the code for you, for me because of lack of time. So try to work in our direction so we can work towards yours.
     
  5. Hedgehog-Team

    Hedgehog-Team

    Joined:
    Feb 27, 2011
    Posts:
    1,155
    Hi,

    To do what you want, you can use EasyTouch trigger that call a public method. This function will call the functions depending on the direction of swipe.

    Add this function:
    Code (CSharp):
    1. public void DoAction(EasyTouch.SwipeDirection direction){
    2. if (State != TetrimoState.Fixed && State != TetrimoState.Preview && State != TetrimoState.Spawning) {
    3.     if (State != TetrimoState.Landed && direction == EasyTouch.SwipeDirection.Down)
    4.         StartCoroutine(FallingDown());
    5.  
    6.     if (direction == EasyTouch.SwipeDirection.Right ||  direction == EasyTouch.SwipeDirection.Left)
    7.         StartCoroutine(MoveHorizontal());
    8.  
    9.     // Set "up" as alternative button for Jump (Project => Input)
    10.     if (direction == EasyTouch.SwipeDirection.Up && Time.time > NextSwap) {
    11.         if (this.CanRotate) {
    12.             StartCoroutine(RotateTetrimo());
    13.             NextSwap = Time.time + SwapCooldown;
    14.         }
    15.     }
    16.  
    17.     // Automatic falling down
    18.     if (NextFall < 0) {
    19.         StartCoroutine(FallingDown());
    20.         NextFall = FallingCooldown;
    21.     }
    22.     NextFall -= FallingSpeed * Time.deltaTime;
    23. }
    24. }
    Add an EasyTouch trigger component on the object setup like this :
    upload_2015-7-27_17-1-45.png
     
    pokeking likes this.
  6. pokeking

    pokeking

    Joined:
    May 13, 2015
    Posts:
    42
    thank you very much, that's saved me on making this game :D