Search Unity

Sending variables between scripts [SOLVED]

Discussion in 'Scripting' started by Rodrigo G., Dec 9, 2009.

  1. Rodrigo G.

    Rodrigo G.

    Joined:
    Dec 9, 2009
    Posts:
    7
    Hi folks, i'm a new unity user and, as everybody says, i'm surely asking a newbie question, but i have a little problem now, trying to change a variable on a script and the change being listened from another script.

    I can read the first two changes on my variable "a". First, when the object reach point X, variable "a" is a string: "Left side", and when my object reach point Y, variable "a" is another string: "Right side". At this moment, my other script reads both changes in variable "a" without problems.

    The problem is that when the object reach point X again and the other script doesnt seem to read that change.

    First Script "VerifyPoint", attached to the moving object.
    Code (csharp):
    1. var a : String;
    2.  
    3. function Update () {
    4.    
    5.     if(transform.position.x < -5){
    6.         a = "Left Side";
    7.     }
    8.    
    9.     if(transform.position.x > 5){
    10.         a = "Right Side";
    11.     }
    12.    
    13.    
    14. }
    Second script, "PointVerifyed", attached to other object:
    Code (csharp):
    1. var verifying : VerifyPoint;
    2.  
    3. function Update () {
    4.     Debug.Log(verifying.a);
    5. }
    So, im not understanding correctly the behavior of variables, or debuging or Update function, but the variable seem to pass in firsts changes, but cant repeat previous changes.

    I made this "simpler" example with only two changes, trying to understand why a bigger one project with changes in every direction on XYZ axis, doesnt work when the object reach previously reached points. I find the same trouble.

    I hope somebody could undertand the trouble, and expect anybody can explain how to pass variables from one script to another, in a widely simple way?.

    Thanks.
     
  2. llde_chris

    llde_chris

    Joined:
    Aug 13, 2009
    Posts:
    205
    The variables are being changed, it's your console that's removing duplicate print statements.

    Click "Collapse" on the console window to toggle it off.

    Collapse should be off by default IMO.

    That or maybe collapse should collapse by source file/line number instead, that would be much more useful I think.
     
  3. Rodrigo G.

    Rodrigo G.

    Joined:
    Dec 9, 2009
    Posts:
    7
    This solve the "unchanging" variable problem.

    Wow!! :eek:, i would never think that the problem were there. Thanks, llde_chris.

    Now i can continue with my little experiment.... :wink: