So Im trying to make a building system where the player can connect two objects with a series of objects between them, by dragging from one of the objects to the other. However Im quite new to Unity and can find no tutorials on this subject.
screenshot of the idea
I need it to place objects between the squares above when the player clicks on one of them and then drags to the other. Also to clarify, I do NOT looking for a drag and drop system…
So far I have been trying to detect where the player has started to hold the mouse button down and where they stop holding it down; to connect the two objects.
void OnMouseOver()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
var placedTower = Instantiate(tower, new Vector3(transform.position.x, transform.position.y, -1f), Quaternion.identity);
ocupiedBy = 1;
Debug.Log("Tower Placed at " + placedTower.transform.position);
}
if (Input.GetKeyDown(KeyCode.Mouse1) && ocupiedBy == 1)
{
startValue = (int)transform.position.x;
Debug.Log(startValue);
if (Input.GetKeyUp(KeyCode.Mouse1) && ocupiedBy == 1)
{
int endValue = (int)transform.position.x;
Debug.Log(endValue);
for (int i = startValue; i != endValue; i++)
{
Debug.Log(i);
}
}
}
}
The first IF statement is totally fine, I just thought to add it for more context.
I am super stumped and would be grateful for any help or even a solution for this.
Adam Revere is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.