Hi, so I’m trying to use a grab box to move objects on a 2d grid. The grabber can move on the 8x8 grid, and will be able to select what is currently under it.
Are there any hints you can give as to how I can implement this? Right now all I have is a control built into my grabber object:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovementScript : MonoBehaviour {
public Vector2[][] myArray = new Vector2[8][];
int yVal = 0;
int xVal = 0;
// Use this for initialization
void Start () {
print("Hello World");
transform.position = new Vector3(0, 0, -10);
for (int i = 0; i < 8; i++)
{
myArray *= new Vector2[8];*
for (int n = 0; n <8; n++)
{
myArray*[n] = new Vector2(i, n);*
}
}
print(“Array initialized.”);
}
* // Update is called once per frame*
* void Update () {*
if (Input.GetKeyDown(“up”))
{
if (yVal < 7) {
yVal++;
transform.position = new Vector2(myArray[xVal][yVal].x, myArray[xVal][yVal].y);
}
}
if (Input.GetKeyDown(“down”))
{
if (yVal > 0)
{
yVal–;
transform.position = new Vector2(myArray[xVal][yVal].x, myArray[xVal][yVal].y);
}
}
if (Input.GetKeyDown(“left”))
{
if (xVal > 0)
{
xVal–;
transform.position = new Vector2(myArray[xVal][yVal].x, myArray[xVal][yVal].y);
}
}
if (Input.GetKeyDown(“right”))
{
if (xVal < 7)
{
xVal++;
transform.position = new Vector2(myArray[xVal][yVal].x, myArray[xVal][yVal].y);
}
}
}
}
So right now just the basic movement functions.