Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Tetriis attack style destruction

Discussion in 'Scripting' started by lucked, Jun 13, 2012.

  1. lucked

    lucked

    Joined:
    Jul 11, 2010
    Posts:
    111
    hi i´m with one problem i make the playable game style tetris attack but i´m with problem for verify the blocks if has collision with 3 or more blocks :s
    i want verify all the blocks when has more than 3 and destroy
    can help me?
     
  2. CanOfColliders

    CanOfColliders

    Joined:
    Oct 27, 2011
    Posts:
    23
    How about tracking a number of how many collisions a block has, and adding/decreasing it using OnColliderEnter/Exit?

    Something like (c#)

    Code (csharp):
    1. int collisions = 0;
    2.  
    3.     void Update()
    4.     {
    5.         if (collisions >= 3)
    6.             Debug.Log("3 or more collisions.");
    7.     }
    8.    
    9.     void OnCollisionEnter()
    10.     {
    11.         collisions++;
    12.     }
    13.    
    14.     void OnCollisionExit()
    15.     {
    16.         if (collisions > 0)
    17.             collisions--;
    18.     }
    hope this helps.
     
  3. lucked

    lucked

    Joined:
    Jul 11, 2010
    Posts:
    111
    i dont think use collision is the better solution :S