void Update()
{
mouse = transform.GetComponent().ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0.0f));
if (Input.GetKeyDown(KeyCode.Alpha1))
{
ObjectInt = 1;
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
ObjectInt = 2;
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
ObjectInt = 3;
}
if (Input.GetKeyDown(KeyCode.Tab))
{
ObjectInt = 0;
}
//ShowObject and Instatiate if Mouse1 Pressed.
ActiveObjects[ObjectInt].SetActive(true);
ActiveObjects[ObjectInt].transform.position = new Vector2(mouse.x, mouse.y);
if (Input.GetMouseButtonDown(0))
{
Instantiate(Objects[ObjectInt], new Vector2(mouse.x, mouse.y), Quaternion.identity);
Debug.Log("Placed");
}
}
After my change the “mouse” value the IF statements and anything else below doesn’t work, Though this is possibly very simple I can’t work it out, IF i move mouse below the if statements they work but still none of the important stuff below mouse, Hope someone can help.
Is mouse a Vector 3? Are you trying to place an object where the mouse is? If you make a variable Vector 3 mouse, and define mouse this way:
mouse = Camera.main.ScreenToViewportPoint(Input.mousePosition);
And then do this:
if (Input.GetMouseButtonDown(0))
{
Instantiate(Objects[ObjectInt], mouse, Quaternion.identity);
Debug.Log("Placed");
}
I think that would do the trick.
That isn’t tested in Unity, I don’t have access to it, but will in about 90 minutes, so let me know if that works for you, and if now, let me know what your errors are.