- Home /
Getting updated variables from another script
Hey!
Im having problems accessing a variable from another script. Or, i can access it, it just does`nt update with the new information. I made a simple script to illustrate my problem:
function Update ()
{
transform.Translate(0,0.1,0);
}
This is the script which i attached an object to. The initial y position to the object is 0. Now i have another object in the scene with this script attached:
var target:Transform;
function Update ()
{
print(target.position.y);
}
Where the transform variable is assigned to the first object. The problem now is that all i get printed out is the initial position to the first object. I want to print out the updated position as its moving, and not just the start position (whitch it is doing now). Any ideas?
(PS. I already asked something similar in another question, but that was about cameramovement, and it was sorta answered, so i decided to post this problem to a new question.)
This should work. Check if the Collapse button is pressed in the console view - when active, it doesn't show similar lines, driving us crazy!
Are you sure you have the right transform assigned? I just made that mistake, otherwise this code works.
yup, im sure its the right one. I get the initial position from it, so i know its the one i want :P Its just that its the position in the next frame whitch i dont get. (The update)
Answer by Berenger · Feb 24, 2012 at 05:11 AM
In the second object's inspector, clic on the target's name to highlight the corresponding object and make sure that's the one you want.
Also, make sure both objects are enable and that their components with the update loops are enabled.
Answer by James Tima · Feb 25, 2012 at 03:12 AM
The code is ok ,u can check position of a object change or not in inspector view while running game.or check print or transform line in under update function.
Your answer
Follow this Question
Related Questions
Move an object toward an angle in 2d space 0 Answers
Confused about GameObject and Transform 1 Answer
Rotation not going past 180? 2 Answers
Trouble with raycasting 0 Answers