samedi 1 août 2020

In Unity3d my Score doesnt work without hardcoding the if Statement

So my problem is that the players x postion = to the score he reached. But i want to turn the counter off after an specific amount got reached. My problem is I cant do the If Statement without hardcoding the comparing value.

//public text value for the Text
    public Text scoreText;
    //Takes the player Transform
    public Transform player;

    public int bossFightMeter = 2000;

    // Update is called once per frame
    void Update()
    {   //compares the postion on x with an value (check how to solv it without hard coding it)
        if (player.position.x < bossFightMeter) 
        {
            //The X postion of the player is converted to string and displayed on the Text output 
            scoreText.text = player.position.x.ToString("0");   //set to 0 so it counts in full numbers
        }
    }

if I write

if(player.position.x < 2000)
{
   ...
}

then it actully works but i dont wanna hardcode it like this.

Aucun commentaire:

Enregistrer un commentaire