Accessing variables from different scripts.

I know this has been asked multiple times but nothing has worked for me so far…i tried GetComponent but i got errors, i used these lines :
var options: Options = GetComponent(Options);

options.WaitTime;

What i’m trying to do is access the WaitTime variable from the “Options” script so i can use it with the “Play” script.

my code so far (regarding the WaitTime variable)on the “Play” script is this :

 var waitTime: Options = GetComponent(Options); 
     waitTime.WaitTime;


    
    
    
 


  
  

 
  


function wait(){

yield WaitForSeconds(waitTime);
lol = false;




(i call the wait function through "OnMouseExit")

AND ON MY OPTIONS SCRIPT IT IS THIS:

static  var WaitTime : int;






function wait(){

yield WaitForSeconds(WaitTime);
lol = false;




}



function Update(){
if( WaitTime < 0){

     WaitTime= 0;
   
}

if( WaitTime >60){

     WaitTime= 60;
   
}



}
(Again, i call the wait function on "OnMouseExit")

In my “Options” script i have the variable WaitTime and i want this variable to have the same value on both scripts ( and a 3rd one later on ).When i use those scripts i get 2 errors though:

1.Assets/MyScripts/Play.js(75,21): BCE0024: The type ‘UnityEngine.WaitForSeconds’ does not have a visible constructor that matches the argument list ‘(Options)’.

2.Assets/MyScripts/Play.js(4,15): BCE0034: Expressions in statements must only be executed for their side-effects.

I don’t know if i was clear to what i wanted but, thanks in advance!!!

Thank you guys for your replies , i solved the problem :smiley:

in the pIay script i put these Iines:

 var waitTime: Options = GetComponent(Options); 

//a bunch of code here


  function wait(){

  yield WaitForSeconds(waitTime.WaitTime);
  lol = false;




}

plus…i used what Gauco Beini Ramos Filho mentioned as well.

So thank you all, for making my day

You know this questions has many answers on Unity Answers or even Unity Forum or even articles here http://unitygems.com/

One thing to keep in mind, avoid static even though you have been told to. This is not because it would not work here but more likely because you seem not to know what they are for yet and they would probably make you think they are for this purpose when they are not.

As for now, you have a target script and a fetcher script.

Target.js

var targetVar: AnyType;

Fetcher.js

var scriptReference : Target;

function Start(){
    // If script on different object
    scriptReference = GameObject.Find("ObjectName").GetComponent(Target);
    // If script on same object
    scriptReference = gameObject.GetComponent(Target);
}

function KungFoo(){
    scriptReference.targetVar = value;
}

Hey, try this:

public static var WaitTime : int;