• 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 /
  • Help Room /
avatar image
Question by Bleackk · Mar 18, 2016 at 06:43 PM · c#uiscene-loadingwaitforseconds

Scene Change after some time when achieving a certain Score C#

Hello everyone, i'm making a simple game where you gather blocks, each block = 1 to score. It's based on the " Roll a Ball " Tutorial. Now here's what i want to do.

I need to change the scene after let's say 5 seconds using " WaitForSeconds " so i can display a " Good Job " Text and Change the Game Scene to the Next level after those 5 seconds.

Here's the script I wrote, i used a " private bool counting = false; " to check if the score was reached.

 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 using System.Collections;
 
 public class PlayerControlls : MonoBehaviour {
 
     private Rigidbody rb;
     private int count;
 
     public float speed;
     public float waitTime;
     public Text countText;
     public Text winText;
     private bool counting = false;
 
     void Start () 
     {
         StartCoroutine (changeDelay ());
         rb = GetComponent<Rigidbody> ();
         count = 0;
         SetCountText ();
         winText.text = "";
     }
 
     void FixedUpdate () 
     {
         float mH = Input.GetAxis ("Horizontal");
         float mV = Input.GetAxis ("Vertical");
 
         Vector3 move = new Vector3 (mH, 0, mV);
 
         rb.AddForce (move * speed * Time.deltaTime);
     }
     void OnTriggerEnter(Collider other) 
     {
         if (other.gameObject.CompareTag ("Pick Up"))
         {
             other.gameObject.SetActive (false);
             count = count + 1;
             SetCountText ();
         }
     }
     void Update()
     {
         if (counting) 
         {
             changeDelay ();
             SceneManager.LoadScene ("Level2");
         }
     }
 
     IEnumerator changeDelay ()
     {
         yield return new WaitForSeconds (10);
     }
 
     void SetCountText()
     {
         countText.text = "Score: " + count.ToString();
         if (count >= 1 && !counting)
         {
             counting = true;
             winText.text = "Good Job";
         }
     }
 }


ANY help would be apreciated. Unity is updated to the latest STABLE version, so 5.3.4

Comment

People who like this

0 Show 0
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

  • Sort: 
avatar image
Best Answer

Answer by Bleackk · Mar 18, 2016 at 07:02 PM

Allready fiured it Out. Here's the difference :) For anyone looking for the same thing

     IEnumerator changeDelay ()
     {
         SetCountText ();
         yield return new WaitForSeconds (10);
         SceneManager.LoadScene ("Level2");
     }
 
     void SetCountText()
     {
         countText.text = "Score: " + count.ToString();
         if (count >= 1 && !counting)
         {
             counting = true;
             winText.text = "Good Job";
         }
     }
 }

Instead of Invoking the IEnumerator in SetCountText i reversed the Process.

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

132 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to add multiple yield return new wait for seconds inside an IEnumerator? 1 Answer

How to restart a level only for 2 times? 1 Answer

error CS1736: The expression being assigned to optional parameter `i' must be a constant or default value 0 Answers

Save timer score between scenes? (C#) 5 Answers

Make a button load the previous scene a player was on? 0 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