Passing Value

Hello,

I’m just wondering if somebody could help me figure out how to pass a value from a script to another script. Looks like this question has been asked a lot but somehow I cannot seem to do it right the way I want. I have posted the code I have so far that works and what I would like instead. The following code works when I pass the value as a global variable but I would like to set num1 from the function Start() instead such as but that does seem to work

-----------------------------------below code work-----------------------------------
SCRIPT1:
Static var num1 = 13;

SCRIPT2:
var num1Value = script1.num1
function OnCollisionEnter(collision : Collision){

num1.GetComponent(TextMesh).text = “” + num1Value;
}

But instead I would like In script1 to set up the variable num1 from inside the Start() function and being able to pass it to script2 such as:

SCRIPT1
static var num1;
function Start(){
num1 = 13
}

SCRIPT2
var num1Value = script1.num1
function OnCollisionEnter(collision : Collision){

num1.GetComponent(TextMesh).text = “” + num1Value;
}

I hope my post makes sense. Thanks for your help.

Think of scripts as Components

(if any of this is wrong, please correct me)

Very component is pretty closed off from the world - this makes it easier to write them independent of each other but a bit of pain talking to each other.

var someScript : ExampleScript;
someScript = GetComponent (ExampleScript);
someScript.VarFromExampleScript = 0.0;

Thanks for you response. I will try that.