Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by mihail5482 · Jan 21, 2016 at 07:10 PM · 2d gametouchgrid2d platformergrid based game

Move object to grid

How to implement such a grid and drag items into the net.

Example

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 Verusoft · Jan 21, 2016 at 09:52 PM

I recognized your example. It's mobile game called 1010! You can implement it in Unity very easily. Here are a few tips:

  1. Create one white image (You will change color of this sprite by Color value in Sprite renderer) and use it as 2D Sprite prefab.

  2. Create class OneItem with public variable Vector2 position;

  3. In Start() method Instantiate your prefab 100 times and setup position according to example

  4. For grad and drop use something like this:

 bool dragging = false;
 Vector2 dragEndPosition;
 void OnMouseDown()
 {
     dragging = true;
 }    
 void OnMouseUp()
 {
     if (dragging) {
         //TODO: here use dragEndPosition to change values in net 
     }
     dragging = false;
 }
 void Update()
 {
     if (dragging)
     {
         RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
         if(hit.collider != null)
         {
             dragEndPosition = hit.collider.gameObject.getComponent<OneItem>().position;
         }
     }
 }

  1. Use your imagination and create whatever features you want.

Comment
Add comment · Show 6 · 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 mihail5482 · Jan 22, 2016 at 09:26 AM 0
Share

Thank you for your comment. Could you make a small example, because I have something not fully understand. I have a good idea of the game. If you will have a desire to cooperate, write skype miha54822

avatar image mihail5482 · Jan 22, 2016 at 08:10 PM 0
Share

hit.collider.gameObject.getComponent().position; Why do I need it? Create class OneItem with public variable Vector2 position;

avatar image mihail5482 mihail5482 · Jan 29, 2016 at 08:50 AM 0
Share

hit.collider.gameObject.getComponent().position; Why do I need it? Create class OneItem with public variable Vector2 position;

avatar image ShadyProductions · Jan 22, 2016 at 08:23 PM 0
Share

100 objects in a scene for a mobile game isn't very optimalized :P

avatar image Verusoft · Jan 22, 2016 at 09:18 PM 0
Share

@mihail5482 I can make small demo, but you have to be patient I'm kinda busy right now

@ShadyProductions 100 static sprites is no problem on mobile devices at all. Of course you can optimize it. It was just first idea.

avatar image mihail5482 Verusoft · Jan 26, 2016 at 02:37 PM 0
Share

I can still look for yours demo? If you have a little time, help please.

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

45 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

0.32 by 0.32 2D grid in Unity using Mathf.Round? 0 Answers

[2D] Trying to make my character jump using addForce, but it's not working.,Rigidbody2d.AddForce isn't working. 0 Answers

My collisions dont detect in gridbased system (check if in certain area) 0 Answers

Which gameObject is touched when touch at overlap gameObjects? 1 Answer

Walking around 2D planets? 1 Answer


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