Move object to grid
How to implement such a grid and drag items into the net.
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:
Create one white image (You will change color of this sprite by Color value in Sprite renderer) and use it as 2D Sprite prefab.
Create class OneItem with public variable Vector2 position;
In Start() method Instantiate your prefab 100 times and setup position according to example
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;
}
}
}
Use your imagination and create whatever features you want.
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
hit.collider.gameObject.getComponent().position; Why do I need it? Create class OneItem with public variable Vector2 position;
hit.collider.gameObject.getComponent().position; Why do I need it? Create class OneItem with public variable Vector2 position;
100 objects in a scene for a mobile game isn't very optimalized :P
@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.
I can still look for yours demo? If you have a little time, help please.
Your answer
Follow this Question
Related Questions
0.32 by 0.32 2D grid in Unity using Mathf.Round? 0 Answers
Can someone help me make a simple 2d endless runner script? 0 Answers
Problem with my dash ability, 1 Answer
Tetris grid 1 Answer