Hello guys im wondering i have ray cast system in my game and currently it fire raycast when left mouse button is clicked, i want the raycast to fire when button is held, it is actually when button is held down but it only fire once in a click, i want it to do raycast until button is released, any ideas?
I currently have it through event onMouseDown which is fired only once when button is pressed, i kinda want to change it to keep firing it every frame.
I did try to put it in update method but it doesnt recognize a mouse position, is there a way i can get the position of mouse besides onmousedown event ?
Listen for mouse events and update local this.x and this.y values from that event. Nothing else on mouse move/drag. On mouseup you can disallow raycasts. No actual raycasting on mouse events.
In your postUpdate then you do a raycast using the values stored in this.x and this.y. Raycast should not listen for mouse events and should not use the event data directly. It is opposite to what tutorial example does, but it is done so for simplicity.
that means it is raycasting each frame and even though im moving my mouse, it took only position of it when i clicked , not when moving, i know there is mousemove event but that i cant use unfortunately, because the click is important, here is example: i have 3 boxes next to each other, when i click on first it change the color of the box mouse is pointing on, when player hold mouse button and get over another box it change color too and so on until all boxes are painted.