Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jan_Julius · Sep 01, 2014 at 11:24 AM · gridpuzzle

Make my grid fall and spawn new objects

Hello.

I'm currently creating a puzzle game where I create a grid, I then want the grid to drop and fill in the spaces of the objects that dissapear and spawn new objects at the top of the playboard (somewhat like candycrush) What is an easy way to achieve this? here you can see what I currently have.

http://i.gyazo.com/2700a64c7e1157d7fcf8b345deafa054.png

 using UnityEngine;
 using System.Collections;
 
 public class Grid : MonoBehaviour {
 
         public GameObject Hex;
         public GameObject MoleCule;
         public int gridWidthInHexes = 10;
         public int gridHeightInHexes = 10;
         private float hexWidth;
         private float hexHeight;
 
         void Start(){
             setSizes();
             createGrid();
         }
     
         void setSizes(){
             hexWidth = Hex.renderer.bounds.size.x;
             hexHeight = Hex.renderer.bounds.size.y;
         }
         
         Vector3 calcInitPos(){
             Vector3 initPos;
             initPos = new Vector3(-hexWidth * gridWidthInHexes / 2f + hexWidth / 2, 0,
                                   gridHeightInHexes / 2f * hexHeight - hexHeight / 2);
             
             return initPos;
         }
         
         public Vector3 calcWorldCoord(Vector2 gridPos){
             Vector3 initPos = calcInitPos();
             float offset = 0;
             if (gridPos.y % 2 != 0)
                 offset = hexWidth / 2;
             
             float x =  initPos.x + offset + gridPos.x * hexWidth;
             float y = initPos.y - gridPos.y * hexHeight * 0.29f;
             return new Vector3(x, y, 0);
         }
         
 
         void createGrid()
         {
             GameObject hexGridGO = new GameObject("HexGrid");
             
             for (float y = 0; y < gridHeightInHexes; y++)
             {
                 for (float x = 0; x < gridWidthInHexes; x++)
                 {
                     GameObject hex = (GameObject)Instantiate(Hex);
                     GameObject molecule = (GameObject)Instantiate(MoleCule);
                     Vector2 gridPos = new Vector2(x, y);
                     hex.transform.position = calcWorldCoord(gridPos);
                     hex.transform.parent = hexGridGO.transform;
                     molecule.transform.position = calcWorldCoord(gridPos);
                     molecule.transform.parent = hexGridGO.transform;
                     
                 }
             }
         }
 
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Quaker_SDR · Sep 01, 2014 at 12:04 PM

Calculate the column count regularly, if the count gt reduced, Add 1 from the top.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jan_Julius · Sep 02, 2014 at 08:26 AM 0
Share

How would I execute this? especially with them moving down to the empty spot for example if one in the bottom gets removed every single on on top if it has to move down one and then add a new one from the top, how can I achieve this?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Problem searching grid using recursive function 2 Answers

Block puzzle (1010) help 0 Answers

Puzzle piece rotation 0 Answers

How to let player move for specific number of times in gird base system.,Implement a move system in grid where player can move for specific number then dies if he did not meet game end/ 0 Answers

Stacking Lego pieces 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges