- Home /
Question by
Golden_Gamer · Feb 08, 2018 at 08:49 PM ·
c#vector3mousepositionscreentoworldpointinput.mouseposition
Trying To Find Mouse Position On Tap
I'm trying to see if I can move a trigger to where the characters taps/clicks. I've done lots of researching and looked over lots of other people who had a similar-ish problem, which eventually lead me to this; but the object now doesn't move at all when I click.
public int TapDamage = 10;
Vector3 StartPos;
Vector3 p = new Vector3();
Camera c = Camera.main;
Event e = Event.current;
Vector2 mousePos = new Vector2();
private void Start()
{
StartPos = gameObject.transform.position;
}
void MovingClickBox()
{
if (Input.GetMouseButtonDown(0) == true)
{
mousePos = Input.mousePosition;
mousePos.x = e.mousePosition.x;
mousePos.y = c.pixelHeight - e.mousePosition.y;
p = c.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, c.nearClipPlane));
gameObject.transform.position = mousePos;
}
}
private void FixedUpdate()
{
MovingClickBox();
}
Comment
Best Answer
Answer by hexagonius · Feb 08, 2018 at 09:45 PM
you're overriding mousePos you just read the mouse position into completely. remove those lines.
Your answer
Follow this Question
Related Questions
Input.mousePosition to ScreenToWorldPoint 1 Answer
Convert Mouse Position to move a cube on 1-axis. 1 Answer
Distribute terrain in zones 3 Answers
Problem with ScreenToWorldPoint and touches (C#) 2 Answers
MousePosition Offset 0 Answers