Accessing game object from separate scripts

Hi there,

I am having trouble accessing multiple game objects from a separate script.

In my game I have a grid of 3d square objects, 5 x 5. What I would like to do is
find out when one of the tiles is clicked and based on what tile out of the 25 is clicked update an array.

I understand that i could attach a script to each square object that would register a mouse click and then update the array. But obviously from a functional perspective I would like to have one script that can access all the objects and find out when they receive a mouse click!

Any help would be greatly appreciated!

Craig

Well each of your objects would need some kind of variable “boolean hasBeenClicked” anyway, so you need a script for every object anyway. You could assign the same tag to all objects and check the status using a controll script which scans the scene with GameObject.FindObjectsWithTag(…).

Another approach would be to do some kind of raycasting to detect which object has been clicked. This could allow you to get away with just one script, but it may be a little more complicated.

Just some thoughts