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 VLunarFangV · May 27, 2013 at 10:11 AM · javascripttransform.positionpublic variable

Transform position to a public variable

I'm currently trying to make an object drop at a certain speed that is changed constantly throughout the game. I've used a public variable in another script. When the code is run, the object just sits there doing nothing. What should I be doing instead?

 #pragma strict
 var Turn : float;
 
 function Update () {
     transform.position.y=transform.position.y-Start.Speed;
     transform.Rotate(0, 0, 1*Turn);
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by Pangamini · May 27, 2013 at 10:42 AM

In JS you can't have more public variables in different scripts? I am not sure if i understand your question;

But i am sure that what you want to achieve is that the object is moving downwards at certain speed; The Update function is called in every frame and the framerate is not constant, therefore your code will cause the object to move in framerate affected speed. To fix that, multiply your speed values by Time.deltaTime .

 transform.position.y = transform.position.y - 1 * Time.deltaTime;

This will move your object one unit per second, no matter what's the framerate Same for the rotation

Comment
Add comment · Show 4 · 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 VLunarFangV · May 27, 2013 at 11:00 AM 0
Share

Oh hell, I forgot to change it back to show the bug I have. I've changed it to what it originally was so you can have a proper look at it. $$anonymous$$y bad? :S

But what I want is this:

  • Object falls at certain speed

  • When object is destroyed (used in another script) it changes the Speed variable.

So far it just sits there when I run it with the buggy script.

avatar image Pangamini · May 27, 2013 at 11:03 AM 0
Share

"When object is destroyed (used in another script)" ? You really have to be more clear

avatar image VLunarFangV · May 27, 2013 at 11:31 AM 0
Share

Sorry. I've included code in another script that destroys the object when it hits a specific object, but that sort of thing is getting kinda irrelevant. I think the only thing we need to focus on is just line 5.

avatar image Owen-Reynolds · May 27, 2013 at 04:44 PM 0
Share

Try a search on "unity finding var in another script." Some people use statics (which I$$anonymous$$HO always needs to be ripped out later.) The GetComponent method works for more things.

I'd also maybe not use "Start" for the other script name. Seems it might get confused with the Start function.

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

15 People are following this question.

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

Related Questions

How would I move an Object after collision? 1 Answer

Script error: respawn upon collission 2 Answers

Move different objects from point A to B with objects having different time to move b/w these points. 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Getting error transform.position assign attempt for "Player" is not valid on rigidbody 2 Answers


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