I have Script01.js and Script02.js. In Script01.js, I have a variable named "animState". animState goes from 0 - 4 throughout the script, depending on what events take place. Now, I want to be able to tell when animState is a certain value in Script02.js. It would be used like this:
I tried making a new instance of the class:
and then dragged Script01.js into the var slot of the Script02.js.
I inserted a print into Script02.js to see what's happening:
It's value shows up as 0.
Oh, and the scripts are on different objects.
What am I doing wrong, can anyone help me with this?
Instead of a variable for the script on the GameObject, have a variable for the GameObject to which the script is attached. You can get to the script like this:
(Forgive me if there are some syntax errors; I usually use C#.) The variable script01Ref should let you manipulate the script you care about.
answered Sep 15, 2010 at 05:06 PM
You can use both the solutions given here, but I honestly don't see a problem with how you described you did it. It should work.
I think you just have some other error in your code, you dragged the wrong thing in the inspector or you put the print statement in the wrong place. If you want you can upload your project somewhere, and I can try and take a look. Or you can post the code for both scripts here, and a snapshot of the inspectors...
answered Oct 19, 2010 at 12:08 AM
answered Dec 18, 2010 at 01:57 PM