Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sunwinkl · May 16, 2017 at 04:43 PM · triggerlevelpickupcounterscoring

Load next level when reach score

Hello, i have a script game manager that has a purpose to load the next level after reaching the certain number of score..each level has a different score.

But, the problem is, im confusing and still noob in programming, the score are not reset when reach the next level. I Mean, the score from earlier level still count. Maybe you can see the script exactly in Void SetCountText() how to correct that one.

If anyone know's how to fix this please answer here I really appreciated that Thanx a lot

Here are the script, there are 2 scripts that related.

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

public class GameManager : MonoBehaviour {

 public static GameManager instance = null;
 public GameObject scoreTextObject;
 public Text WinText;

 int score;
 Text scoreText;


 // Use this for initialization
 void Awake () { 
     if (instance == null)
         instance = this;
     else if (instance != null)
         Destroy (gameObject);    
     scoreText = scoreTextObject.GetComponent<Text> ();
     SetCountText ();
     WinText.text = "";
 } 

 public void Collect(int passedValue, GameObject passedObject)
 {
     passedObject.GetComponent<Renderer>().enabled = false;
     passedObject.GetComponent<Collider> ().enabled = false;
     Destroy (passedObject, 0.3f);
     score = score + passedValue;
     SetCountText ();


 }

 void SetCountText ()
 {
     scoreText.text = "" + score.ToString ();
     if (score >= 100) {
         WinText.text = "Congrats \nGo To The Next Level";
         Invoke( "NextLevel", 3.0f );
     }
     if (score >= 200) {
         WinText.text = "Congrats \nGo To The Next Level";
         Invoke ("NextLevel1", 3.0f);
     }
     if (score >= 300) {
         WinText.text = "Congrats \nYou Win";
         Invoke( "NextLevel2", 3.0f );
     }

 }
 void NextLevel ()
 {
     score=0;
     Application.LoadLevel ("Test6");
 }
 void NextLevel1 ()
 {
     score=0;
     Application.LoadLevel ("Test7");
 }
 void NextLevel2 ()
 {
     Application.LoadLevel ("Win");
 }

}

using System.Collections; using UnityEngine;

public class Collectable : MonoBehaviour {

 public int value;
 public float rotateSpeed;

 void Update()
 {
     gameObject.transform.Rotate (Vector3.up * Time.deltaTime * rotateSpeed);
 }
 void OnTriggerEnter()
 {
     GameManager.instance.Collect (value, gameObject);

     AudioSource source = GetComponent<AudioSource> ();
     source.Play ();
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kamil1064 · May 16, 2017 at 05:34 PM

Hi @sunwinki, Version of unity is always nice looking in description :) but try to add this:

 using UnityEngine.SceneManagement;

And later in your void NextLevel1():

 SceneManager.LoadScene(0);
 // or
 SceneManager.LoadScene("winScene");

https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

pickup counter and timer help 0 Answers

Touch the same GUITexture button to Pick Up and Drop a Rigidbody Game Object 0 Answers

destroy object after Application.LoadLevel 1 Answer

Level requested not loading, prev. one is instead? 2 Answers

GUI text like GTA 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges