- Home /
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!
Answer by BiG · Apr 30, 2012 at 07:23 PM
And with this?
var OldScore = PointSystem.score;
function Update() {
if (PointSystem.score > OldScore){
OldScore = PointSystem.score;
transform.Translate(0,1,0);
}
}
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
Well, for my point of view, +1 to this, because it's equal to the solution of $$anonymous$$e :) I've just posted it some seconds before.
However, pay attention, because you've "encapsulated" the RaiseWall inside the Update.