so i have multiple objects( Grid of cubes) that i want to have a variable called canUse; what i am asking is if i can have this one variable be local to the gameObject, but then acces each variable in another script?
If you’re raycasting for another object, you can get the hit gameobject from the hit-info and from there the script component.
So assuming a script CubeScript
on your cubes:
var canUse = true; // change in inspector as needed
// ... more stuff
… your raycasting script can do:
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
var go = hit.transform.gameObject;
if (go.tag == "Foo") { // some test for hitting cubes
var cubeScript = go.GetComponent(CubeScript);
if (cubeScript && cubeScript.canUse) {
// do stuff
}
}
}