x


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 this 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 this, 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!

more ▼

asked Apr 30 '12 at 07:18 PM

Woutervd gravatar image

Woutervd
25 1 2 3

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

And with this?

var OldScore = PointSystem.score;

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

answered Apr 30 '12 at 07:23 PM

BiG gravatar image

BiG
4.7k 4 13 49

Thank you!

Apr 30 '12 at 10:33 PM Woutervd
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Apr 30 '12 at 07:24 PM

Seth Bergman gravatar image

Seth Bergman
7k 10 16 28

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.

Apr 30 '12 at 07:30 PM BiG

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

Apr 30 '12 at 10:42 PM Seth Bergman
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3453
x341
x322
x41

asked: Apr 30 '12 at 07:18 PM

Seen: 346 times

Last Updated: Apr 30 '12 at 10:42 PM