- Home /
How can my blocks be selected by sliding over them rather than needing to be individually clicked?
My game is about selecting blocks. The function I use to input this is OnMouseDown. Once clicked, a series of if statements are used to see if that block can be selected.
However, the only way for the block to be recognized that it is being clicked is if I went over it and clicked it. Since the game is about selecting these blocks quickly, individually tapping every block could get very tedious very quickly.
For example, I want to select the blocks "1", "+", and "3". Currently, I have to tap and raise my finger 3 separate times for all 3 to be selected. What I intend is for me to press down on "1" and while still pressing down on the screen, slide my finger over to "+" and then "3" and finally raise my finger.
I tried to use the OnMouseDrag() function but that kept on selecting and deselecting blocks on every frame.
What can I use to allow my blocks to be selected when slid over AND individually selected?
Here is the Minimum reproducible code:
void OnMouseDown()
{
if (canBeSelected)
{
if (!selected && SelectedBlocks.Count <= 6)
{
if (firstSelect && gameObject.tag != "Operation" && SelectedBlocks.Count < 1)
{AddBlock();}
else if (!firstSelect && SelectedBlocks.Count >= 1)
{
if(SelectedBlocks[SelectedBlocks.Count - 1].tag != gameObject.tag)
{
if ((int)gameObject.transform.position.x <= (int)SelectedBlocks[SelectedBlocks.Count - 1].transform.position.x + 1 && (int)gameObject.transform.position.x >= (int)SelectedBlocks[SelectedBlocks.Count - 1].transform.position.x - 1)
{
if ((int)gameObject.transform.position.y <= (int)SelectedBlocks[SelectedBlocks.Count - 1].transform.position.y + 1 && (int)gameObject.transform.position.y >= (int)SelectedBlocks[SelectedBlocks.Count - 1].transform.position.y - 1)
{AddBlock();}
}
}
}
}
else if (selected)
{
SpawnBlocks.RemoveBlock(myID, false);
audioData.PlayOneShot(removeAudio);
}
}