Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Tacitus86 · May 25, 2016 at 04:06 PM · unityeditoryield waitforsecondsbeginners

yield WaitForSeconds unexpected symbol

Hello All. I'm currently adding some functionality to the first "Roll A Ball" application as I learn Unity for the first time. I wanted to display the Win text for X number of seconds so I found the yield WaitForSeconds function. The issue is that the compiler in MonoDevelop-Unity application gives me an error:

 Assets/Scripts/PlayerController.cs(13,17): error CS0246: The type or namespace name `List`1' could not be found. Are you missing a using directive or an assembly reference?

All I did was add this to the "SetCountText()" function as below:

     void SetCountText(){
         countText.text = "Count: " + count.ToString ();
         if (count >= 17) {
             winText.text = "This game is terrible. You should get a refund.";
             yield WaitForSeconds(5f);
         }
     }

Any ideas? Am I missing some special namespace or something? I'm currently using: using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI;

Comment
Add comment · Show 1
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
avatar image Tacitus86 · May 31, 2016 at 02:12 PM 0
Share

Can I bump this? Still need a good answer as this still doesn't seem to work even done as described in the suggested links.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · May 25, 2016 at 04:07 PM

WaitForSeconds is a class, so it needs to be instantiated with the 'new' keyword. Try this:

 yield return new WaitForSeconds(5f);

Also, it only works in a function that supports it, namely a function that returns IEnumerator. Check this article out for more info.

Comment
Add comment · Show 3 · 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
avatar image Tacitus86 · May 25, 2016 at 05:45 PM 0
Share

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

public class PlayerController : $$anonymous$$onoBehaviour {

 public float speed;
 public Text countText;
 public Text winText;

 private int count;

 private List<GameObject> disabledObjects = new List<GameObject>();

 private Rigidbody rb;

 void Start(){
     rb = GetComponent<Rigidbody> ();
     count = 0;
     SetCountText ();
     winText.text = "";
     StartCoroutine (checkEnd());
 }

 // Physics code. Called before physics calculations
 void FixedUpdate(){
     float moveHorizontal = Input.GetAxis ("Horizontal");
     float moveVertical = Input.GetAxis ("Vertical");

     Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

     rb.AddForce (movement*speed);
 }

 void Update(){
     if (count >= 17) {
         // reset game
         count = 0;
         rb.$$anonymous$$ovePosition(new Vector3 (0.0f, 0.5f, 0.0f));
         SetCountText ();
         foreach (GameObject a in disabledObjects) {
             a.SetActive (true);
         }
     }
 }

 void OnTriggerEnter(Collider other){
     if (other.gameObject.CompareTag("Pickup")){
         other.gameObject.SetActive(false);
         disabledObjects.Add (other.gameObject);
         count++;
         SetCountText ();
     }
 }

 void SetCountText(){
     countText.text = "Count: " + count.ToString ();
 }

 IEnumerator checkEnd(){
     if (count >= 17) {
         winText.text = "This game is terrible. You should get a refund.";
         yield return new WaitForSeconds (5.0f);
         winText.text = "";
     }
 }

}

avatar image FortisVenaliter Tacitus86 · May 25, 2016 at 07:05 PM 0
Share

Did you read the article I linked to? It tells you how to start coroutines properly. Hint: It's how you're calling the method.

avatar image Tacitus86 FortisVenaliter · May 25, 2016 at 07:39 PM 0
Share

Yep. I tried calling checkEnd(), StartCoroutine(checkEnd()) as well as StartCoroutine("checkEnd"); - Like in updated code in previous comment (I Edited it). And it still doesn't seem to work.

avatar image
0

Answer by alpsaruhan96 · Nov 25, 2020 at 11:09 PM

hey, none of this worked? well, try this one...

     IEnumerator WaitForSec(float secounds)
     {
     Debug.Log("our wait has started");
     yield return new WaitForSeconds(secounds);
     Debug.Log("our wait has started");
     }




Comment
Add comment · Show 2 · 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
avatar image alpsaruhan96 · Nov 25, 2020 at 11:10 PM 0
Share

oh no wait

avatar image alpsaruhan96 alpsaruhan96 · Nov 25, 2020 at 11:17 PM 0
Share

there now try it

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity do not open the Creator Kit: Beginner code in the right version. 0 Answers

Game Optimization , free from glitch , high resolution , real time shadows 0 Answers

How can I edit materials on the model I brought from Sketch-up?,Hi, 1 Answer

Match making in Photon 0 Answers

How to release patches/updates and implement a patcher/updater for your unity game ? 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