Noob question on passing a variable

Hi everyone - I know there are resources that explain this and I’ve read them, but I just can’t seem to understand how to do a very simple thing:

I have GUI buttons that set a variable called Hdirection to different values when the user clicks them. Then I have another script to which I want to pass those values. I’ve tried using GetComponent, and a few other things that I think should work but I just get errors. Could someone tell what the scripts would be in each script to do this?

Thanks for any hints you’ve got, sorry this question is so dumb.

you can try this thread:

http://forum.unity3d.com/viewtopic.php?t=41079

Thanks Ivkoni – I’ve seen that threat and spent a lot of time in the “Accessing other game objects” and tried the examples (I think number 4 is closest to what I want), but I’m just not getting it. I’ll keep trying. If there’s any way you could post two scripts – one that sets a variable, and another that receives it (say for something simple like a print(variable); that would be awesome, but thanks either way - I’ll try going through that explanation again.

I personally like using static vars for things like this.

here are 3 scritps. You can attach them to your camera.

staticData.js

public static var myInt : int = 0;

setMyInt.js

function Update() {
	if(Input.GetKeyDown(KeyCode.UpArrow)){
		staticData.myInt++;
	}
	if(Input.GetKeyDown(KeyCode.DownArrow)){
		staticData.myInt--;
	}
}

printMyInt.js

function Update () {
if(Input.GetKeyDown(KeyCode.P)){
	print(staticData.myInt);
}
}

I like putting my static variables separately (in a separate script) but you don’t have to. You can declare a static var in any script you want.

Thanks Ivkoni! This looks like just what I need, I’ll try it out. Really appreciate the extra effort – I don’t know why all this is so unintuitive for me, but it really helps to have it all spelled out like you’ve done. Hope some day I can help you out with something.

NZ