I’m doing a top-down-shooter type of football game and I want the field to move “up” once I reach a certain score, and “down” if I go below a certain score. What I have doesn’t work, but I thought it may be a good starting point.
Here’s something I tried to get the field moving using the score:
void Update()
{
MoveupField();
}
public void MoveupField()
{
//'field moving code'
if (Player.Score > 99)
{
transform.Translate(Vector3.down, Space.World);
transform.position = new Vector3(transform.position.x, 1f, transform.position.z);
}
if (Player.Score > 199)
{
transform.position = new Vector3(transform.position.x, 14f, transform.position.z);
}
if (Player.Score > 299)
{
transform.position = new Vector3(transform.position.x, 27f, transform.position.z);
}
if (Player.Score > 399)
{
transform.Translate(Vector3.down, Space.World);
}
}
Forgive me if this is a silly question, but have you checked what Player.Score actually is, via Debug.Log? In the code you’ve posted, if it’s 99 or less, nothing is going to happen.
First, you’re making it way more complicated than it is. Don’t bother with translate or x / z. Just change transform.position.y = 1, 14, 27 or whatever. And you don’t need to do those tests every frame, only during the event “the score just changed”.
Anyway, your code should work already. Use some print() to see if it goes inside your if(). I suspect it doesn’t, maybe Player.Score is wrong, or maybe the Update function isn’t even run, which would mean the script isn’t attached to an activated game object, or isn’t enabled.