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.
var a : String;
function Update () {
if(transform.position.x < -5){
a = "Left Side";
}
if(transform.position.x > 5){
a = "Right Side";
}
}
Second script, “PointVerifyed”, attached to other object:
var verifying : VerifyPoint;
function Update () {
Debug.Log(verifying.a);
}
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.