hey there, im new round here,
i was wondering if i could get some help with an issue im having, i have previous experience in programming, mainly in ruby, and from moving to 3d development in unity i have picked up java pretty quick with it being object orientated programming, but the issue im having withing unity is accessing variables from outside of the object, currently i am trying to create visual effects when swimming underwater, i am currently trying to attach a fog to my camera, and only allow the fog to appear if the player is underwater, so i thought it would be pretty simple, and i have followed some of the tuts abouting accessing variables from external objects but to no avail, so here is my current setup:
first my class that stores the swimming variable, which is called GameData :
public var Swimming;
function Start () {
Swimming = false;
}
function Update () {
}
the above script is attached to my first person controller, which i have named “Player”
so then i add a fog image effect to my main camera, in which i am trying to only allow to show if Swimming is true, at the moment im just trying to access the variable and get the value like so:
var go = GameObject.Find("Player");
var GD = go.GetComponent("GameData");
var swimming = GD.Swimming;
although i am not managing to get the value 
from following the unity scripting reference i thought what i currently have should work 
I am somewhat of a novice with Unity as of now but hopefully this helps. It seems easier to me to simply create a new camera rather then directly altering the single camera’s individual variables within a script.
I would create two camera objects in the game, one without fog and one with. You will also need two camera variables in your desired script. Then use your script to switch between the two unique camera objects (dragging the camera objects from hierarchy to the correct script variables within inspector to access both directly in script). That way you will not have to access values within an object you can just select a different object to use, which seems way easier for me thus far.
hmmm, i don’t mind the idea of using 2 cameras, but it is inevitable that i am going to need to access and control variables from outside the current object, as my water is made like so:
the water has 2 planes, one for the top, and one for the bottom, then these planes are children of a box object, which is used for collision, and they are placed on the top face of the box obviously scaled correctly.
so with that in mind the way the fog works is the fog has a set too and from Y point, so the idea behind it is that the fog only generates from the bottom to the top of the box, the reason for this is simple, when the camera is partially out of the water, i don’t want fog to be on the world above.
so when i turn the fog on i am going to have to get the current Y and height of the box to set the Y location that the fog is generated too and from, so i am definitely going to need to learn how to access and change variables from outside of the object, but i will play around with the two camera idea, as it will probably be easier to just switch camera to the one with fog attached when i need it 
I think all you need to do is remove the quotes around GameData when accessing the component. So line 2 should read like this:
var GD = go.GetComponent(GameData);
i tried that to begin with, the problem seems to persist that it does not know the script exists, i cant remember the error to be specific as im away from home at the moment, but in whichever case it says the function cannot be found on the object, even though it is, its got me totally baffled as usually something like this would be pretty simple, by the way im writing this in java, as i failed to mention earlier, im not sure if i have got any sintax wrong as some of the coding references are not specific on what they are wrote in, on the matter is there any way that i can create a script that does not exist apart of an object and apart of the system, i.e im creating a swimming variable now that is only checked once for the main player so i could just have one main script that handles all variables for the player that is constant upon the system and doesnt require to be built on an object
hey there, id like to mark this as resolved, after returning home and looking deeper into the matter, from reading how the compilation of the scripts work within unity, i found out that all the scripts inside standard assets are compiled first, and that i cannot access other scripts from said scripts that are below the standard assets directory, this was my problem as the script i made was within the root directory so it could not find any reference to it, but simply moving it into the standard assets folder solved my issue 