- Home /
Question by
Danisuper · Oct 03, 2013 at 08:09 PM ·
transformdetectionmouseclick
HELP C# script mouse position doesn't work
hi everybody i'm very new in unity and i am developing a simple 2d game.I have a problem with a script that musts detect mouse position,it works but positions are wrong here's the code: void Update() { if (Input.GetMouseButton(0)) {
ClickFunction();
}
}
void ClickFunction()
{
Vector3 pos_mouse=transform.position += new Vector3(Input.mousePosition.x,Input.mousePosition.y, 0);
Debug.Log(pos_mouse);
}
all gameObjects,for example in the x axis they are at 58/80 and in the y axis 55/35. But when i run the script it detects me position like 1356,0,0 and for every click detected positions increases. What is wrong??? thanks in advance. if this can help you with answers i am developing a 2d game.
Comment
Answer by Mill0698 · Oct 03, 2013 at 09:30 PM
For one, you are trying to have a Vector3 = a Vector3 += a new Vector3.
Try
void ClickFunction()
{
Vector3 pos_mouse=transform.position + new Vector3(Input.mousePosition.x,Input.mousePosition.y, 0);
Debug.Log(pos_mouse);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613115248im_/https://answers.unity.com/themes/thub/images/avi.jpg)