Search Unity

2d endles Runner How change levels when u reach lets say 2000 points

Discussion in '2D' started by berserkeris, Jun 18, 2017.

  1. berserkeris

    berserkeris

    Joined:
    Jun 18, 2017
    Posts:
    5
    im creating 2d endles runer like game and i need help i dont cnow how to load level when u reach sertyain amount of points can anyone help?
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
  3. berserkeris

    berserkeris

    Joined:
    Jun 18, 2017
    Posts:
    5
     
  4. berserkeris

    berserkeris

    Joined:
    Jun 18, 2017
    Posts:
    5
    so i need ad this on score manager ?
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Yeah, if you have that already, add it in there.
     
  6. berserkeris

    berserkeris

    Joined:
    Jun 18, 2017
    Posts:
    5
    Ty i try at home and let cnow does it worked
     
  7. berserkeris

    berserkeris

    Joined:
    Jun 18, 2017
    Posts:
    5
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;

    public class ScoreManager : MonoBehaviour {

    public Text scoreText;
    public Text hiScoreText;

    public float scoreCount;
    public float hiScoreCount;

    public float pointsPerSecond;

    public bool scoreIncreasing;

    // Use this for initialization
    void Start () {



    if (PlayerPrefs.HasKey ("highscore") != null)
    {
    hiScoreCount = PlayerPrefs.GetFloat ("highscore");
    }
    }

    // Update is called once per frame
    void Update () {
    if (scoreIncreasing)
    {
    scoreCount += pointsPerSecond * Time.deltaTime;
    }
    if(scoreCount > hiScoreCount)
    {
    hiScoreCount = scoreCount;
    PlayerPrefs.SetFloat ("highscore", hiScoreCount);
    }

    scoreText.text = "score: " + Mathf.Round (scoreCount);
    hiScoreText.text = "highscore :" + Mathf.Round (hiScoreCount);




    }


    public void AddScore(int pointsToAdd)
    {
    scoreCount += pointsToAdd;
    }





    }

    where too put it ?
     
  8. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Please take a moment to look at this post, which shows you how to add code so it looks nicer in the forums: https://forum.unity3d.com/threads/using-code-tags-properly.143875/

    You add it where you add to your score; You check if the score is 2,000 pts then change levels if it is (after updating your highscore if applicable).