• 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 Woutervd · Apr 30, 2012 at 07:18 PM · javascriptvariablesleveltransform.translate

I want to translate an object when score changes but it doesn't work

Hello! I have built a simple score system that gives you a point whenever you fall off-world. I now want to increase the height of my walls by 1 meter everytime t$$anonymous$$s happens. I've written the following script:

  function Update() {
         var OldScore = PointSystem.score;
         if (PointSystem.score > OldScore) {
             transform.Translate(0,1,0);}
         }

If I put it like t$$anonymous$$s, the wall doesn't move because OldScore is always the same as PointSystem.score. However, if I put the defining of var OldScore outside function Update( ) the wall lifts off indefinitely. The solution is probably very logical, but I can't find it.

Thank you for your help!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by BiG · Apr 30, 2012 at 07:23 PM

And with t$$anonymous$$s?

 var OldScore = PointSystem.score;

 function Update() {
    if (PointSystem.score > OldScore){
       OldScore = PointSystem.score;
       transform.Translate(0,1,0);
    }
 }
Comment
Add comment · Show 1 · 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 Woutervd · Apr 30, 2012 at 10:33 PM 1
Share

Thank you!

avatar image
3

Answer by Seth-Bergman · Apr 30, 2012 at 07:24 PM

var OldScore = PointSystem.score;

 function Update() {
        
         if (PointSystem.score > OldScore) 
           RaiseWall();
        
 }
 function RaiseWall()
 {
 if (PointSystem.score > OldScore)
 {
 OldScore = PointSystem.Score;
  transform.Translate(0,1,0);}
 }
 

//super simple example

Comment
Add comment · Show 2 · 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 BiG · Apr 30, 2012 at 07:30 PM 0
Share

Well, for my point of view, +1 to this, because it's equal to the solution of mine :) I've just posted it some seconds before.

However, pay attention, because you've "encapsulated" the RaiseWall inside the Update.

avatar image Seth-Bergman · Apr 30, 2012 at 10:42 PM 1
Share

D'oh, right you are, fixed it now, and thanks!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Finding what scene number player is on and adding one.... 1 Answer

(VERY BASIC) how to assign a variable to a gameobject 2 Answers

Changing a variable on a different object 2 Answers

Adding varibales from other scripts 3 Answers

Activate line just one time 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