Movemnt multiple object

hi, currently working on small puzzle type game, we have one square object with four arrow texture, what i want when i click on left arrow my object move to left side, so on… so i set up im object as shown in the following image…


attach MovementScript to my Player as shown in image…

my MovementScript code is as follows…


function Update () {

if (Input.GetMouseButtonDown(0)){

var hit: RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

if (hit.collider){

if (hit.collider.tag == “up”){
Debug.Log(“hit up”);
rigidbody2D.velocity = Vector2(0,1);
}
if (hit.collider.tag == “down”){
Debug.Log(“hit down”);
rigidbody2D.velocity = Vector2(0,-1);
}
if (hit.collider.tag == “right”){
Debug.Log(“hit right”);
rigidbody2D.velocity = Vector2(1,0);
}
if (hit.collider.tag == “left”){
Debug.Log(“hit left”);
rigidbody2D.velocity = Vector2(-1,0);
}

}

}

}


every this works perfectly till here,

but when i duplicated the player object, Now if i click left arrow of one object both player is moving left side, I want only selected player should move.

What defines “selected player” in your case? If both player objects are at the same position, then they will both react to the mouse input exactly the same way.

So again, you need to define what you mean by “selected player” or “active player.”

Also please put code inside CODE tags for better readability.

it should move active player, if suppose i have 2 player, if i click on left arrow key of right side player, now only right side player should move to left side not the both one,

sorry but i don’t know how to place my code in code tag here.