Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by manni · Feb 23, 2012 at 11:17 PM · javascripttransformupdate

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.)

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aldonaletto · Feb 23, 2012 at 11:28 PM 2
Share

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!

avatar image manni · Feb 24, 2012 at 04:18 AM 0
Share

I still get the same value :)

avatar image Blazor Ramone · Feb 24, 2012 at 04:45 AM 0
Share

Are you sure you have the right transform assigned? I just made that mistake, otherwise this code works.

avatar image manni · Feb 24, 2012 at 11:46 AM 0
Share

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)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

modifing enemies target inside a radius 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges