Hi,
Can anyone please tell me how to achieve the following in unity,
What i want is to scroll a group of objects to left or right similar to the images shown in above link. When i move them left or right, the objects should slide in the next adjacent slot and the object at one end will appear at another end.
What you describe doesn’t quite match the behavior shown on the page you linked to, I don’t think, but as for your question, there are various ways it could be done.
The way I’d probably do it would be to assign each object a ‘slot’ and derive its x position (or whatever) from that. Moving the objects instantaneously would be a simple matter of ‘cycling’ the slot index for each and then recomputing the position. To get a smoother visual effect though, you’ll most likely want to interpolate between the old position and the new one, probably using a smoothing function such as ease-in-ease-out. (This would be fairly trivial to code, but I imagine you could use iTween for it as well.)
As for the last object ‘wrapping’ around to the other side, you’ll have to decide what sort of effect you want. (I don’t know what these objects are, but options might include duplicating the object and having the ‘new’ one slide in from one side as the ‘old’ one slides off the other side, or having the object move to the other side, e.g. by going behind the other objects.)
Hi Jesse,
Can you tell me how to detect whether my mouse position has changed after the mouse button is pressed and in which direction it is moving. Hope you understand what i want to say. Basically i am asking how to read the mouse inputs after the button is pressed down.
When the mouse button is pressed, save the x coordinate of the current mouse position and set a flag indicating that you’re ‘waiting for a mouse motion’.
Each update that you’re waiting for a mouse motion, grab the x coordinate of the current mouse position and compare it to that of the position you stored in step 1.
If it’s less than or greater than the original x coordinate, clear the ‘waiting for a mouse motion’ flag, and initiate a scroll in the corresponding direction.
If the mouse button is released and the ‘waiting for a mouse motion’ flag is set, clear the flag.
If you want the controls to be less sensitive, you could require that the mouse move a certain distance on the x axis before the scroll is initiated, and/or require that it be moved at or faster than a specified speed.
[Edit: Depending on how you want the controls to work, you might be able to use the ‘Mouse X’ input axis rather than (or in addition to) storing the original mouse position.]