Skip to main content


Showing posts from March, 2014

How to use mouse as touch input in unity

Hi guys, Here is a simple way to use mouse inputs as touch inputs. In the Below script i used a simple swipe logic same as my previous blog on simple way to do swipe with touch inputs. As you can see both script are pretty much the same, i just replaced touch events with mouse events.


publicclassMouseAsTouch : MonoBehaviour {

privateVector2fp; //firstfingerposition
privateVector2lp; //lastfingerposition
publicTransformplayer; //Dragyourplayerhere




voidCheckMouseAsTouch(EventTypetouch, Vector3currentPosition){

if(touch.ToString() == "mouseDown"){
fp = newVector2(currentPosition.x,currentPosition.y);
lp = newVector2(currentPosition.x,currentPosition.y);

if(touch.ToString() == "mouseDrag"){
lp = newVector2(currentPosition.x,currentPosition.y);

if(touch.ToString() == "mouseUp"){

RTS game like unit selection in unity

Hi guys, today i am posting a simple way to select a bunch of characters using mouse drag and command them to move to a specific place on map.
I have 2 script which handles everything, actually there is nothing much to handle, just select your unit and move them wherever you want.

First script is for Camera, this script check all the characters that falls in mouse drag limit and put them in an array, and when user click anywhere in the map they move to there respective positions.

For pathfinding i am using Unity NaveMesh, Its easy to setup and very easy to use.

Lets check the video given below, you can see that how i am dragging my mouse to select player and moving them.

I am using a very simple logic to achieve what you saw in video, When user drag his mouse I call a function named "FindPlayersInDragLimit" where i pass 2 values firstPostion and lastPosition and based on those values, script choose max 4 characters and assign them to an array list named "selectedUnit.