Moving objects one by one with mouse click

Hi there,

I am working on chest game. I have one move script for all of my objects movement. I need to find which one is clicked and so move it. because at this moment they all move . I tried to set a flag when mouse enter on GUI but again they move together. How can I separate these objects from each other and just move one of them at time without moving the rest.

Any help would be highly appreciated.

Okay...

Make a camera, add a controller (So that it moves with WASD and arrow keys... so the player kinda moves around the map)...

Now, you want to look up ray casts (I can't help you here because they make no sense to me, and I havn't taken time to actually try and learn them).

So, with the ray casting, you want to name the pieces accordingly, and make an if statement with the ray cast...

if it hits _ object, enable script A.

Now, on script A, it'll show the spots it can move... And you'll take this, being, if the spot already has a player on it, you make this red (You can look up particle system colors, or make different particle systems for each kind of move...).

So, now, you have if player raycast an object, enable script A, and now you want another ray cast, where if player raycast a good spot, move object to it, BUT if player raycast a bad spot (Taken spot), show a message (For this look at the GUI Label and Strings with them), and this says, Can no do! to the player, and doesn't do anything...

Now, you have it so that it enables that piece's movements, and makes it move...

Notice how I broke down EVERY piece of this whole thing, and their is still more you need, movements, valid spots, how to tell valid spots, etc. You're going to have to do this for every piece...

Now, it's not all hard...

Make a 2D Array

[][][][][]
[][][][][]
[][][][][]
[][][][][]

X is the player.

[][][][][]
[][][][][]
[][][][][]
[][][X][][]

If pawn and hasn't moved, it can go either 1 or 2 spots.

[][][][][]
[][][X][][]
[][][X][][]
[][][][][]

If it's a knight...

[][][][][]
[][X][][X][]
[][][][][]
[][][][][]

If a King....

[][][][][]
[][][][][]
[][X][X][X][]
[][X][][X][]

Etc. See where I'm going with this? It's very well possible, and it'll have a lot of the same code, you just have to do the work =).

Good luck!

PS: This is how I'd do it... It might be easier haha.

Chess, right?

You'll need to keep your game logic distinct from the scripts that animate the pieces (as Justin pretty much says above, one script per type of piece (king, pawn, etc.)

If this is PC/Mac/Web, you should be able to use Collider stuff (read manual) to detect mouse click and activate the motion (after checking against current game state of course). If this is mobile, you'll have to use the raycast stuff. Google around, there are posts here and on the forum how to use that. And in the manual, of course.